Fred Drake | 32c562b | 1999-04-19 21:20:13 +0000 | [diff] [blame] | 1 | \section{\module{colorsys} --- |
| 2 | Conversions between color systems} |
| 3 | |
| 4 | \declaremodule{standard}{colorsys} |
| 5 | \modulesynopsis{Conversion functions between RGB and other color systems.} |
| 6 | \sectionauthor{David Ascher}{da@python.net} |
| 7 | |
| 8 | The \module{colorsys} module defines bidirectional conversions of |
| 9 | color values between colors expressed in the RGB (Red Green Blue) |
| 10 | color space used in computer monitors and three other coordinate |
| 11 | systems: YIQ, HLS (Hue Lightness Saturation) and HSV (Hue Saturation |
| 12 | Value). Coordinates in all of these color spaces are floating point |
| 13 | values. In the YIQ space, the Y coordinate is between 0 and 1, but |
| 14 | the I and Q coordinates can be positive or negative. In all other |
| 15 | spaces, the coordinates are all between 0 and 1. |
| 16 | |
| 17 | More information about color spaces can be found at |
Brett Cannon | 35415da | 2003-12-11 04:37:24 +0000 | [diff] [blame] | 18 | \url{http://www.poynton.com/ColorFAQ.html}. |
Fred Drake | 32c562b | 1999-04-19 21:20:13 +0000 | [diff] [blame] | 19 | |
| 20 | The \module{colorsys} module defines the following functions: |
| 21 | |
| 22 | \begin{funcdesc}{rgb_to_yiq}{r, g, b} |
| 23 | Convert the color from RGB coordinates to YIQ coordinates. |
| 24 | \end{funcdesc} |
| 25 | |
| 26 | \begin{funcdesc}{yiq_to_rgb}{y, i, q} |
| 27 | Convert the color from YIQ coordinates to RGB coordinates. |
| 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{rgb_to_hls}{r, g, b} |
| 31 | Convert the color from RGB coordinates to HLS coordinates. |
| 32 | \end{funcdesc} |
| 33 | |
| 34 | \begin{funcdesc}{hls_to_rgb}{h, l, s} |
| 35 | Convert the color from HLS coordinates to RGB coordinates. |
| 36 | \end{funcdesc} |
| 37 | |
| 38 | \begin{funcdesc}{rgb_to_hsv}{r, g, b} |
| 39 | Convert the color from RGB coordinates to HSV coordinates. |
| 40 | \end{funcdesc} |
| 41 | |
| 42 | \begin{funcdesc}{hsv_to_rgb}{h, s, v} |
| 43 | Convert the color from HSV coordinates to RGB coordinates. |
| 44 | \end{funcdesc} |
| 45 | |
| 46 | Example: |
| 47 | |
| 48 | \begin{verbatim} |
| 49 | >>> import colorsys |
| 50 | >>> colorsys.rgb_to_hsv(.3, .4, .2) |
| 51 | (0.25, 0.5, 0.4) |
| 52 | >>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4) |
| 53 | (0.3, 0.4, 0.2) |
| 54 | \end{verbatim} |