class Color(tuple):
A Color object represents a color with red, green and blue
components.
def fromcss(cls, s):
clsCreate 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').
def fromrgb(cls, r, g, b, a=1.0):
clsCreate 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].
def fromhsv(cls, h, s, v, a=1.0):
clsCreate 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].
def fromhls(cls, h, l, s, a=1.0):
clsCreate 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].
def __repr__(self):
selfdef __str__(self):
selfself formatted as a CSS color string.
def r(self):
selfThe red value as an int between 0 and 255.
def g(self):
selfThe green value as an int between 0 and 255.
def b(self):
selfThe blue value as an int between 0 and 255.
def a(self):
selfThe alpha value as an int between 0 and 255.
def rgb(self):
selfThe red, green and blue value as a float tuple with values between 0.0 and 1.0.
def rgba(self):
selfThe red, green, blue and alpha value as a float tuple with values between 0.0 and 1.0.
def hsv(self):
selfself as a HSV ("hue, saturation, value") triple.
All three values are between 0.0 and 1.0.
def hsva(self):
selfself as a HSV+alpha ("hue, saturation, value, alpha") tuple.
All four values are between 0.0 and 1.0.
def hls(self):
selfself as a HLS ("hue, luminance, saturation") triple. All three
values are between 0.0 and 1.0.
def hlsa(self):
selfself as a HLS+alpha ("hue, luminance, saturation, alpha") tuple.
All four values are between 0.0 and 1.0.
def lum(self):
selfThe luminance value from hls.
def combine(self, r=None, g=None, b=None, a=None):
selfReturn a copy of self with some of the values replaced by the
arguments.
def witha(self, a):
selfReturn a copy of self with the alpha value replaced with a.
def withlum(self, lum):
selfReturn a copy of self with the luminosity replaced with lum.
def abslum(self, f):
selfReturn a copy of self with f added to the luminocity.
def rellum(self, f):
selfReturn 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):
selfdef __mul__(self, factor):
selfdef __rmul__(self, factor):
selfdef __div__(self, factor):
selfdef __mod__(self, other):
selfBlends self with the background color other according to the
SVG 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.