blob: dbab7063e106fbda0e19f0b2d2d689ab9d217285 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001: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
Raymond Hettingera1993682011-01-27 01:20:32 +00008**Source code:** :source:`Lib/colorsys.py`
9
10--------------
Georg Brandl116aa622007-08-15 14:28:22 +000011
12The :mod:`colorsys` module defines bidirectional conversions of color values
13between colors expressed in the RGB (Red Green Blue) color space used in
14computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness
15Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color
16spaces are floating point values. In the YIQ space, the Y coordinate is between
170 and 1, but the I and Q coordinates can be positive or negative. In all other
18spaces, the coordinates are all between 0 and 1.
19
Alexandre Vassalotti6461e102008-05-15 22:09:29 +000020.. seealso::
21
22 More information about color spaces can be found at
23 http://www.poynton.com/ColorFAQ.html and
24 http://www.cambridgeincolour.com/tutorials/color-spaces.htm.
Georg Brandl116aa622007-08-15 14:28:22 +000025
26The :mod:`colorsys` module defines the following functions:
27
28
29.. function:: rgb_to_yiq(r, g, b)
30
31 Convert the color from RGB coordinates to YIQ coordinates.
32
33
34.. function:: yiq_to_rgb(y, i, q)
35
36 Convert the color from YIQ coordinates to RGB coordinates.
37
38
39.. function:: rgb_to_hls(r, g, b)
40
41 Convert the color from RGB coordinates to HLS coordinates.
42
43
44.. function:: hls_to_rgb(h, l, s)
45
46 Convert the color from HLS coordinates to RGB coordinates.
47
48
49.. function:: rgb_to_hsv(r, g, b)
50
51 Convert the color from RGB coordinates to HSV coordinates.
52
53
54.. function:: hsv_to_rgb(h, s, v)
55
56 Convert the color from HSV coordinates to RGB coordinates.
57
58Example::
59
60 >>> import colorsys
61 >>> colorsys.rgb_to_hsv(.3, .4, .2)
62 (0.25, 0.5, 0.4)
63 >>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4)
64 (0.3, 0.4, 0.2)