Color
Immutable RGBA color with conversion utilities and interpolation
Use Color.NONE as a sentinel for "no color" (transparent/none). Initialization can now take any supported format directly:
Constructor
Color(args, kwargs)
Flexible initializer to create Color from various formats.
Methods
darken
darken(amount: int) -> Color
Create darker version of this color (preserves alpha)
from_hex
from_hex(hex_str: str) -> Color
Create from hex string
from_name
from_name(name: str) -> Color
Create from CSS color name
from_tuple
from_tuple(rgb: Tuple[int, int, int]) -> Color
Create from RGB or RGBA tuple
interpolate
interpolate(
other: Color,
t: float,
space: ColorSpace = <ColorSpace.LAB: 'lab'>
) -> Color
Interpolate to another color (including alpha channel)
is_none
is_none()
Check if this is the special NONE sentinel (no color)
lighten
lighten(amount: int) -> Color
Create lighter version of this color (preserves alpha)
to_hex
to_hex()
Convert to hex string (#RRGGBB) or 'none'
to_rgb_string
to_rgb_string()
Convert to CSS rgb() or rgba() string for drawsvg or 'none'
to_tuple
to_tuple()
Convert to RGB tuple (without alpha) for rendering
with_alpha
with_alpha(alpha: int) -> Color
Create a new color with different alpha value
Parameters
-
alpha - Alpha value 0-255 (0=transparent, 255=opaque)
Returns
New Color instance with updated alpha
with_opacity
with_opacity(opacity: float) -> Color
Create color with opacity (0.0 to 1.0)
Parameters
-
opacity - Opacity value 0.0 (transparent) to 1.0 (opaque)
Returns
New Color with alpha set from opacity