Color
Immutable RGB color with conversion utilities and interpolation.
Use Color.NONE as a sentinel for "no color" (transparent/none).
Accepted constructor forms::
Color(255, 0, 0) # r, g, b ints
Color("#FF0000") # 6-char hex
Color("#F00") # 3-char hex (expanded to 6)
Color("red") # CSS color name
Color(other_color) # copy
Color((255, 0, 0)) # RGB tuple
Constructor
Color(args, kwargs)
Methods
darken
darken(amount: int) -> Color
Return a darker version by subtracting amount from each channel (clamped to 0).
from_hex
from_hex(hex_str: str) -> Color
Create from a hex string — equivalent to Color(hex_str).
from_name
from_name(name: str) -> Color
Create from a CSS color name — equivalent to Color(name).
from_tuple
from_tuple(rgb: tuple[int, int, int]) -> Color
Create from an RGB tuple — equivalent to Color(rgb).
interpolate
interpolate(
other: Color,
t: float,
space: ColorSpace = <ColorSpace.LAB: 'lab'>
) -> Color
Interpolate toward other at t in the given color space.
is_none
is_none()
Check if this is the special NONE sentinel (no color)
lighten
lighten(amount: int) -> Color
Return a lighter version by adding amount to each channel (clamped to 255).
to_hex
to_hex()
Convert to hex string (#RRGGBB) or 'none'
to_rgb_string
to_rgb_string()
Convert to CSS rgb(r,g,b) string, or 'none' for Color.NONE.
to_tuple
to_tuple()
Convert to RGB tuple (without alpha) for rendering