Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`colorsys` --- Conversions between color systems |
| 2 | ===================================================== |
| 3 | |
| 4 | .. module:: colorsys |
| 5 | :synopsis: Conversion functions between RGB and other color systems. |
| 6 | .. sectionauthor:: David Ascher <da@python.net> |
| 7 | |
| 8 | |
| 9 | The :mod:`colorsys` module defines bidirectional conversions of color values |
| 10 | between colors expressed in the RGB (Red Green Blue) color space used in |
| 11 | computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness |
| 12 | Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color |
| 13 | spaces are floating point values. In the YIQ space, the Y coordinate is between |
| 14 | 0 and 1, but the I and Q coordinates can be positive or negative. In all other |
| 15 | spaces, the coordinates are all between 0 and 1. |
| 16 | |
Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 17 | .. seealso:: |
| 18 | |
| 19 | More information about color spaces can be found at |
| 20 | http://www.poynton.com/ColorFAQ.html and |
| 21 | http://www.cambridgeincolour.com/tutorials/color-spaces.htm. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 22 | |
| 23 | The :mod:`colorsys` module defines the following functions: |
| 24 | |
| 25 | |
| 26 | .. function:: rgb_to_yiq(r, g, b) |
| 27 | |
| 28 | Convert the color from RGB coordinates to YIQ coordinates. |
| 29 | |
| 30 | |
| 31 | .. function:: yiq_to_rgb(y, i, q) |
| 32 | |
| 33 | Convert the color from YIQ coordinates to RGB coordinates. |
| 34 | |
| 35 | |
| 36 | .. function:: rgb_to_hls(r, g, b) |
| 37 | |
| 38 | Convert the color from RGB coordinates to HLS coordinates. |
| 39 | |
| 40 | |
| 41 | .. function:: hls_to_rgb(h, l, s) |
| 42 | |
| 43 | Convert the color from HLS coordinates to RGB coordinates. |
| 44 | |
| 45 | |
| 46 | .. function:: rgb_to_hsv(r, g, b) |
| 47 | |
| 48 | Convert the color from RGB coordinates to HSV coordinates. |
| 49 | |
| 50 | |
| 51 | .. function:: hsv_to_rgb(h, s, v) |
| 52 | |
| 53 | Convert the color from HSV coordinates to RGB coordinates. |
| 54 | |
| 55 | Example:: |
| 56 | |
| 57 | >>> import colorsys |
| 58 | >>> colorsys.rgb_to_hsv(.3, .4, .2) |
| 59 | (0.25, 0.5, 0.4) |
| 60 | >>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4) |
| 61 | (0.3, 0.4, 0.2) |