Skip to content

Color

Color

A utility class containing predefined color constants and methods for color manipulation and conversion.

Methods

Name Kwargs Description
__getitem__ key: str retrieves a predefined color by name (e.g., Color['Red']).

Static methods

Name Kwargs ReturnType Description
hex_to_rgb hex_color: str tuple converts HEX string to RGB tuple.
hsl_to_rgb color: tuple tuple converts HSL (0-1) to RGB (0-255).
rgb_to_hsl color: tuple tuple converts RGB (0-255) to HSL (0-1).
invert / invert_hsl color: tuple | str tuple inverts the given color (makes it negative).
lighten color: tuple, amount: float = 0.2 tuple lightens the color by a given amount (0.0 to 1.0).
darken color: tuple, amount: float = 0.2 tuple darkens the color by a given amount (0.0 to 1.0).
random_rgb None tuple returns a random RGB color.
random_hsl None tuple returns a random HSL color.
text_color_for_bg bg_color: tuple tuple returns Black or White depending on background luminance for readability.
with_float_alpha color: tuple, alpha: float tuple returns color with an added alpha channel (0.0 to 1.0).
with_alpha color: tuple, alpha: int tuple returns color with an added alpha channel (0 to 255).
mix *colors tuple mixes several colors together and returns the average RGB.
get_color color: str, default=None tuple | None safely retrieves a predefined color by name.

Getters

Name ReturnType Description
Any Color Name tuple access predefined colors directly as attributes (e.g., Color.AliceBlue, Color.Black, Color.White).

Use case

...#Not provided

Created with GGen v1.1.0 for nevu_ui v0.7.5