Color utility functions and predefined color constants.
from_hex(hex: str) → Colorfrom_hex(hex: str) → ColorCreate a Color from a hex string.
Supports multiple hex formats:
Args
hex : Hex color string (with or without '#' prefix).Returns
Color : New Color object from the hex string.
Examples :
from_hex("#FF00FF") # Magenta, full opacity
from_hex("#FF00FF80") # Magenta, 50% opacity
from_hex("#F0F") # Same as "#FF00FF"
from_hex("RGB") # Without '#' prefix
from_hsv(h: float, s: float, v: float, a: float = 1.0) → Colorfrom_hsv(h: float, s: float, v: float, a: float = 1.0) → ColorCreate a Color from HSV(A) values.
Args
h : Hue angle (0-360).s : Saturation (0-1).v : Value/brightness (0-1).a : Alpha (0-1). Defaults to 1.0.lerp(a: Color, b: Color, t: float) → Colorlerp(a: Color, b: Color, t: float) → ColorLinearly interpolate between two colors.
Performs component-wise linear interpolation between start and end colors. All RGBA channels are interpolated independently.
Args
a : Start color (when t=0.0).b : End color (when t=1.0).t : Blend factor. Values outside [0,1] will extrapolate.Returns
Color : New interpolated color.
Examples :
lerp(Color.RED, Color.BLUE, 0.5) # Purple (halfway between red and blue)
lerp(Color.BLACK, Color.WHITE, 0.25) # Dark gray
invert(color: Color) → Colorinvert(color: Color) → ColorReturn the inverse of a color by flipping RGB channels.
The alpha channel is preserved unchanged.
Args
color : The color to invert.Returns
Color : New Color with inverted RGB values (255 - original value).
Example :
invert(Color(255, 0, 128, 200)) # Returns Color(0, 255, 127, 200)