Website hosting service by Active-Venture.com
  

 Back to Index

14.7 colorsys -- Conversions between color systems

The colorsys module defines bidirectional conversions of color values between colors expressed in the RGB (Red Green Blue) color space used in computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1.

More information about color spaces can be found at http://www.inforamp.net/%7epoynton/ColorFAQ.html.

The colorsys module defines the following functions:

 
rgb_to_yiq( r, g, b)
Convert the color from RGB coordinates to YIQ coordinates.
 
yiq_to_rgb( y, i, q)
Convert the color from YIQ coordinates to RGB coordinates.
 
rgb_to_hls( r, g, b)
Convert the color from RGB coordinates to HLS coordinates.
 
hls_to_rgb( h, l, s)
Convert the color from HLS coordinates to RGB coordinates.
 
rgb_to_hsv( r, g, b)
Convert the color from RGB coordinates to HSV coordinates.
 
hsv_to_rgb( h, s, v)
Convert the color from HSV coordinates to RGB coordinates.

Example:

>>> import colorsys
>>> colorsys.rgb_to_hsv(.3, .4, .2)
(0.25, 0.5, 0.4)
>>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4)
(0.3, 0.4, 0.2)

  

 

2002-2004 Active-Venture.com Webhosting Service

 

Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to http://python.org/doc/

 

Cheap domain registrar provides cheap domain registration, buy domain name and domain transfer from $5.95/year only   Cheap domain registration : Buy domain name and enjoy comprehensive free services