ll.color – RGB colors and color model conversion
ll.color provides classes and functions for handling RGBA colors.
- class ll.color.Color[source]
Bases:
tupleA
Colorobject represents a color with 8-bit red, green and blue components and opacity.- classmethod fromcss(s: str) ll.color.Color[source]
Create a
Colorobject 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
Colorobject from the red, green, blue and alpha valuesr,g,banda. 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
Colorobject from the hue, saturation and value valuesh,sandvand 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
Colorobject from the hue, luminance and saturation valuesh,landsand 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]
selfas a HSV tuple (“hue”, “saturation”, “value”). All three values are between 0.0 and 1.0.
- hsva() Tuple[float, float, float, float][source]
selfas a HSV+alpha tuple (“hue”, “saturation”, “value”, “alpha”). All four values are between 0.0 and 1.0.
- hls() Tuple[float, float, float][source]
selfas a HLS tuple (“hue, luminance, saturation”). All three values are between 0.0 and 1.0.
- hlsa() Tuple[float, float, float, float][source]
selfas 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
selfwhere the luminance has been replace withlum.
- witha(a: int) ll.color.Color[source]
Return a copy of
selfwith the alpha value replaced witha.
- abslight(f: Union[int, str]) ll.color.Color[source]
Return a copy of
selfwithfadded to the HLS lightness.
- rellight(f: Union[int, str]) ll.color.Color[source]
Return a copy of
selfwhere the lightness has been modified: Iffis positive the lightness will be increased, withf==1giving a lightness of 1. Iffis negative, the lightness will be decreased withf==-1giving a lightness of 0.f==0will leave the lightness unchanged.
- abslum(f: Union[int, str]) ll.color.Color[source]
Return a copy of
selfwherefhas been added to the lum value.
- rellum(f: Union[int, str]) ll.color.Color[source]
Return a copy of
selfwhere the luminance has been modified: Iffis positive the luminance will be increased, withf==1giving a luminance of 1. Iffis negative, the luminance will be decreased withf==-1giving a luminance of 0.f==0will 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
selfwith some of its components replaced by the arguments. If a component is nont passed (or the valueNoneis 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 colorcthe following printsTruethree times:<?print c.invert().r() == 255 - c.r()?> <?print c.invert().g() == 255 - c.g()?> <?print c.invert().b() == 255 - c.b()?>
fspecifies 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
selfwith the background colorotheraccording to the CSS specification
- ll.color.css(value: str, default: Optional[str] = <object object>, /) ll.color.Color[source]
Create a
Colorobject from the CSS color stringvalueviaColor.fromcss().If
valueis no valid CSS color string anddefaultis given, returndefaultinstead.
- 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
c1andc2.
- ll.color.screen(c1: ll.color.Color, c2: ll.color.Color, /) ll.color.Color[source]
Does a negative multiplication of the colors
c1andc2.
- ll.color.mix(*args) ll.color.Color[source]
Calculates a weighted mix of the colors from
args. Items inargsare 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)