ll.color
provides classes and functions for handling RGB colors.
class Color
(tuple
):
A Color
object represents a color with red, green and blue
components.
def __new__
(cls
, r
=0
, g
=0
, b
=0
, a
=255
):
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].
def __repr__
(self
):
def __str__
(self
):
self
formatted as a CSS color string.
def r
(self
):
The red value as an int between 0 and 255.
def g
(self
):
The green value as an int between 0 and 255.
def b
(self
):
The blue value as an int between 0 and 255.
def a
(self
):
The alpha value as an int between 0 and 255.
def rgb
(self
):
The red, green and blue value as a float tuple with values between 0.0 and 1.0.
def rgba
(self
):
The red, green, blue and alpha value as a float tuple with values between 0.0 and 1.0.
def hsv
(self
):
self
as a HSV tuple ("hue, saturation, value").
All three values are between 0.0 and 1.0.
def hsva
(self
):
self
as a HSV+alpha tuple ("hue, saturation, value, alpha").
All four values are between 0.0 and 1.0.
def hls
(self
):
self
as a HLS tuple ("hue, luminance, saturation"). All three
values are between 0.0 and 1.0.
def hlsa
(self
):
self
as a HLS+alpha tuple ("hue, luminance, saturation, alpha").
All four values are between 0.0 and 1.0.
def lum
(self
):
The luminance value from hls
.
def combine
(self
, r
=None
, g
=None
, b
=None
, a
=None
):
Return a copy of self
with some of the values replaced by the
arguments.
def witha
(self
, a
):
Return a copy of self
with the alpha value replaced with a
.
def withlum
(self
, lum
):
Return a copy of self
with the luminosity replaced with lum
.
def abslum
(self
, f
):
Return a copy of self
with f
added to the luminocity.
def rellum
(self
, f
):
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.
def __add__
(self
, other
):
def __mul__
(self
, factor
):
def __rmul__
(self
, factor
):
def __truediv__
(self
, factor
):
def __floordiv__
(self
, factor
):
def __mod__
(self
, other
):
Blends self
with the background color other
according to the
CSS specification
def css
(value
):
def dist
(c1
, c2
):
Return the distance between two colors.
def multiply
(c1
, c2
):
Multiplies the colors c1
and c2
.
def screen
(c1
, c2
):
Does a negative multiplication of the colors c1
and c2
.
def mix
(*args
):
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)