ll.color – RGB colors and color model conversion

ll.color provides classes and functions for handling RGB colors.

class ll.color.Color[source]

Bases: tuple

A Color object represents a color with red, green and blue components and transparency.

__mod__(other)[source]

Blends self with the background color other according to the CSS specification

static __new__(r=0, g=0, b=0, a=255)[source]

Create a Color with the 8 bit red, green, blue and alpha components r, g, b and a. Values will be clipped to the range [0; 255].

__str__()[source]

self formatted as a CSS color string.

a()[source]

The alpha value as an int between 0 and 255.

abslum(f)[source]

Return a copy of self with f added to the luminocity.

b()[source]

The blue value as an int between 0 and 255.

combine(r=None, g=None, b=None, a=None)[source]

Return a copy of self with some of the values replaced by the arguments.

classmethod fromcss(s)[source]

Create a Color object from the CSS color string s. 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 fromhls(h, l, s, a=1.0)[source]

Create a Color object from the hue, luminance and saturation values h, l and s and the alpha value a. The hue value will be used modulo 1.0, luminance, saturation and alpha will be clipped to the range [0; 1].

classmethod fromhsv(h, s, v, a=1.0)[source]

Create a Color object from the hue, saturation and value values h, s and v and the alpha value a. The hue value will be used modulo 1.0, saturation, value and alpha will be clipped to the range [0; 1].

classmethod fromrgb(r, g, b, a=1.0)[source]

Create a Color object from the red, green, blue and alpha values r, g, b and a. All values will be clipped to the range [0; 1].

g()[source]

The green value as an int between 0 and 255.

hls()[source]

self as a HLS tuple (“hue, luminance, saturation”). All three values are between 0.0 and 1.0.

hlsa()[source]

self as a HLS+alpha tuple (“hue, luminance, saturation, alpha”). All four values are between 0.0 and 1.0.

hsv()[source]

self as a HSV tuple (“hue, saturation, value”). All three values are between 0.0 and 1.0.

hsva()[source]

self as a HSV+alpha tuple (“hue, saturation, value, alpha”). All four values are between 0.0 and 1.0.

lum()[source]

The luminance value from hls().

r()[source]

The red value as an int between 0 and 255.

rellum(f)[source]

Return a copy of self where the luminocity has been modified: If f if positive the luminocity will be increased, with f==1 giving a luminocity of 1. If f is negative, the luminocity will be decreased with f==-1 giving a luminocity of 0. f==0 will leave the luminocity unchanged.

rgb()[source]

The red, green and blue value as a float tuple with values between 0.0 and 1.0.

rgba()[source]

The red, green, blue and alpha value as a float tuple with values between 0.0 and 1.0.

witha(a)[source]

Return a copy of self with the alpha value replaced with a.

withlum(lum)[source]

Return a copy of self with the luminosity replaced with lum.

ll.color.dist(c1, c2)[source]

Return the distance between two colors.

ll.color.mix(*args)[source]

Calculates a weighted mix of the colors from args. Items in args 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)
ll.color.multiply(c1, c2)[source]

Multiplies the colors c1 and c2.

ll.color.screen(c1, c2)[source]

Does a negative multiplication of the colors c1 and c2.