ll.color
– RGB colors and color model conversion
ll.color
provides classes and functions for handling RGBA colors.
- class ll.color.Color[source]
Bases:
tuple
A
Color
object represents a color with 8-bit red, green and blue components and opacity.- static __new__(cls, r: int = 0, g: int = 0, b: int = 0, a: int = 255)[source]
Create a
Color
with the 8 bit red, green, blue and alpha componentsr
,g
,b
anda
. Values will be clipped to the range [0; 255].
- classmethod fromcss(s: str) Color [source]
Create a
Color
object from the CSS color strings
. All formats from CSS2 are supported (i.e.'#xxx'
,'#xxxxxx'
,rgb(r, g, b)
,rgb(r%, g%, b%)
,rgba(r, g, b, a)
,rgba(r%, g%, b%, a)
and color names like'red'
).
- classmethod fromrgb(r: int | float, g: int | float, b: int | float, a: int | float = 1.0) Color [source]
Create a
Color
object from the red, green, blue and alpha valuesr
,g
,b
anda
. All values will be clipped to the range [0; 1].
- classmethod fromhsv(h: int | float, s: int | float, v: int | float, a: int | float = 1.0) Color [source]
Create a
Color
object from the hue, saturation and value valuesh
,s
andv
and the alpha valuea
. The hue value will be used modulo 1.0, saturation, value and alpha will be clipped to the range [0; 1].
- classmethod fromhls(h: int | float, l: int | float, s: int | float, a: int | float = 1.0) Color [source]
Create a
Color
object from the hue, luminance and saturation valuesh
,l
ands
and the alpha valuea
. The hue value will be used modulo 1.0, luminance, saturation and alpha will be clipped to the range [0; 1].
- rgb() Tuple[float, float, float] [source]
The red, green and blue value as a float tuple with values between 0.0 and 1.0.
- rgba() Tuple[float, float, float, float] [source]
The red, green, blue and alpha value as a float tuple with values between 0.0 and 1.0.
- hsv() Tuple[float, float, float] [source]
self
as a HSV tuple (“hue”, “saturation”, “value”). All three values are between 0.0 and 1.0.
- hsva() Tuple[float, float, float, float] [source]
self
as a HSV+alpha tuple (“hue”, “saturation”, “value”, “alpha”). All four values are between 0.0 and 1.0.
- hls() Tuple[float, float, float] [source]
self
as a HLS tuple (“hue, luminance, saturation”). All three values are between 0.0 and 1.0.
- hlsa() Tuple[float, float, float, float] [source]
self
as a HLS+alpha tuple (“hue, luminance, saturation, alpha”). All four values are between 0.0 and 1.0.
- withlight(light: int | float) Color [source]
Return a new color with the HLS lightness replaced by
light
- withlum(lum: int | float) Color [source]
Return a copy of
self
where the luminance has been replace withlum
.
- rellight(f: int | float) Color [source]
Return a copy of
self
where the lightness has been modified: Iff
is positive the lightness will be increased, withf==1
giving a lightness of 1. Iff
is negative, the lightness will be decreased withf==-1
giving a lightness of 0.f==0
will leave the lightness unchanged.
- abslum(f: int | float) Color [source]
Return a copy of
self
wheref
has been added to the lum value.
- rellum(f: int | float) Color [source]
Return a copy of
self
where the luminance has been modified: Iff
is positive the luminance will be increased, withf==1
giving a luminance of 1. Iff
is negative, the luminance will be decreased withf==-1
giving a luminance of 0.f==0
will leave the luminance unchanged. All other values return a linear interpolation.
- combine(r: int | float = None, g: int | float = None, b: int | float = None, a: int | float = None) Color [source]
Return a copy of
self
with some of its components replaced by the arguments. If a component is nont passed (or the valueNone
is given) the component will be unchanged in the resulting color.
- invert(f: int | float = 1.0) Color [source]
Return an inverted version of
self
, i.e. for each colorc
the following printsTrue
three times:<?print c.invert().r() == 255 - c.r()?> <?print c.invert().g() == 255 - c.g()?> <?print c.invert().b() == 255 - c.b()?>
f
specifies the amount of inversion, with 1 returning a complete inversion, and 0 returning the original color. Values between 0 and 1 return an interpolation of both extreme values. (And 0.5 always returns medium grey).
- __mod__(other: Color) Color [source]
Blends
self
with the background colorother
according to the CSS specification
- ll.color.css(value: str, default: str | None = <object object>, /) Color [source]
Create a
Color
object from the CSS color stringvalue
viaColor.fromcss()
.If
value
is no valid CSS color string anddefault
is given, returndefault
instead.