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.- classmethod fromcss(s: str) ll.color.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: Union[int, str], g: Union[int, str], b: Union[int, str], a: Union[int, str] = 1.0) ll.color.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: Union[int, str], s: Union[int, str], v: Union[int, str], a: Union[int, str] = 1.0) ll.color.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: Union[int, str], l: Union[int, str], s: Union[int, str], a: Union[int, str] = 1.0) ll.color.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.
- withhue(hue: Union[int, str]) ll.color.Color [source]
Return a new color with the HLS hue replaced by
hue
.
- withlight(light: Union[int, str]) ll.color.Color [source]
Return a new color with the HLS lightness replaced by
light
- withsat(sat: Union[int, str]) ll.color.Color [source]
Return a new color with the HLS saturation replaced by
sat
- withlum(lum: Union[int, str]) ll.color.Color [source]
Return a copy of
self
where the luminance has been replace withlum
.
- witha(a: int) ll.color.Color [source]
Return a copy of
self
with the alpha value replaced witha
.
- abslight(f: Union[int, str]) ll.color.Color [source]
Return a copy of
self
withf
added to the HLS lightness.
- rellight(f: Union[int, str]) ll.color.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: Union[int, str]) ll.color.Color [source]
Return a copy of
self
wheref
has been added to the lum value.
- rellum(f: Union[int, str]) ll.color.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: Optional[Union[int, str]] = None, g: Optional[Union[int, str]] = None, b: Optional[Union[int, str]] = None, a: Optional[Union[int, str]] = None) ll.color.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: Union[int, str] = 1.0) ll.color.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: ll.color.Color) ll.color.Color [source]
Blends
self
with the background colorother
according to the CSS specification
- ll.color.css(value: str, default: Optional[str] = <object object>, /) ll.color.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.
- ll.color.dist(c1: ll.color.Color, c2: ll.color.Color, /) float [source]
Return the distance between two colors.
- ll.color.multiply(c1: ll.color.Color, c2: ll.color.Color, /) ll.color.Color [source]
Multiplies the colors
c1
andc2
.
- ll.color.screen(c1: ll.color.Color, c2: ll.color.Color, /) ll.color.Color [source]
Does a negative multiplication of the colors
c1
andc2
.
- ll.color.mix(*args) ll.color.Color [source]
Calculates a weighted mix of the colors from
args
. Items inargs
are either colors or weights. The following example mixes two parts black with one part white:>>> from ll import color >>> color.mix(2, color.black, 1, color.white) Color(0x55, 0x55, 0x55)