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