Link: start Link: parent Link: First page in set (first) Link: Previous page (previous) Link: Next page (next) Link: Last page in set (last) Link: A plain text version of this page (alternate) Link: The XIST source of this page (alternate) Link: The Python module described in this page (alternate) ll.color ======== RGB color values and color model conversion =========================================== Home > Python software > ll.color Text · XIST · Python Python softwarelist of projects * ll.xistAn extensible XML/HTML generator * ll.ul4cA templating language * ll.urlRFC 2396 compliant URLs * ll.makeObject oriented make replacement * ll.daemonForking daemon processes * ll.sisyphusWriting cron jobs with Python * ll.colorRGB color values and color model conversion * ll.miscMisc utility functions and classes * ll.orasqlUtilities for cx_Oracle * ll.nightshadeServe the output of Oracle functions/procedures with CherryPy * ll.scriptsScripts for UL4 template rendering and URL handling * AploraLogging Apache HTTP requests to an Oracle database * PycocoPython code coverage * DownloadLinks to Windows and Linux, source and binary distributions * Source codeAccess to the Mercurial repositories class Color(tuple): ==================== A Color object represents a color with red, green and blue components. def fromcss(cls, s): ===================== 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'). def fromrgb(cls, r, g, b, a=1.0): ================================== 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]. def fromhsv(cls, h, s, v, a=1.0): ================================== 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]. def fromhls(cls, h, l, s, a=1.0): ================================== 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]. 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 ("hue, saturation, value") triple. All three values are between 0.0 and 1.0. def hsva(self): ================ self as a HSV+alpha ("hue, saturation, value, alpha") tuple. All four values are between 0.0 and 1.0. def hls(self): =============== self as a HLS ("hue, luminance, saturation") triple. All three values are between 0.0 and 1.0. def hlsa(self): ================ self as a HLS+alpha ("hue, luminance, saturation, alpha") tuple. 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 __div__(self, factor): =========================== def __mod__(self, other): ========================== Blends 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.