2007-08-15 11:28:22 -03:00
|
|
|
:mod:`colorsys` --- Conversions between color systems
|
|
|
|
=====================================================
|
|
|
|
|
|
|
|
.. module:: colorsys
|
|
|
|
:synopsis: Conversion functions between RGB and other color systems.
|
2016-06-11 16:02:54 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. sectionauthor:: David Ascher <da@python.net>
|
|
|
|
|
2011-01-26 21:20:32 -04:00
|
|
|
**Source code:** :source:`Lib/colorsys.py`
|
|
|
|
|
|
|
|
--------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The :mod:`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.
|
|
|
|
|
Merged revisions 62914-62916,62918-62919,62921-62922,62924-62942,62944-62945,62947-62949 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62914 | skip.montanaro | 2008-05-08 20:45:00 -0400 (Thu, 08 May 2008) | 4 lines
Add an example about using NamedTemporaryFile() to replace mktemp(). I'm
unclear whether the verbatim text should have been indented or by how much.
........
r62915 | benjamin.peterson | 2008-05-08 20:50:40 -0400 (Thu, 08 May 2008) | 2 lines
reindent example
........
r62927 | georg.brandl | 2008-05-09 02:09:25 -0400 (Fri, 09 May 2008) | 2 lines
#2788: add .hgignore file.
........
r62928 | georg.brandl | 2008-05-09 02:10:43 -0400 (Fri, 09 May 2008) | 2 lines
#2781: fix function name.
........
r62929 | georg.brandl | 2008-05-09 02:18:27 -0400 (Fri, 09 May 2008) | 2 lines
Add a sentence to basicConfig() that is in the docstring.
........
r62930 | georg.brandl | 2008-05-09 02:26:54 -0400 (Fri, 09 May 2008) | 2 lines
Add another link to colorsys docs.
........
r62931 | georg.brandl | 2008-05-09 02:36:07 -0400 (Fri, 09 May 2008) | 2 lines
Add Kodos as a re reference.
........
r62932 | georg.brandl | 2008-05-09 02:39:58 -0400 (Fri, 09 May 2008) | 2 lines
Add a note about using reload().
........
r62933 | andrew.kuchling | 2008-05-09 07:46:05 -0400 (Fri, 09 May 2008) | 3 lines
Update planned release date.
Uncomment PEP 370 section.
Add some module items
........
r62934 | christian.heimes | 2008-05-09 08:19:09 -0400 (Fri, 09 May 2008) | 1 line
Add --user option to build_ext
........
r62948 | mark.dickinson | 2008-05-09 13:54:23 -0400 (Fri, 09 May 2008) | 3 lines
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
negative; fix to return an (appropriately signed) zero instead.
........
r62949 | martin.v.loewis | 2008-05-09 14:21:55 -0400 (Fri, 09 May 2008) | 1 line
Use the CHM file name that Sphinx assigns.
........
2008-05-15 19:09:29 -03:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
More information about color spaces can be found at
|
2019-06-15 11:09:36 -03:00
|
|
|
https://poynton.ca/ColorFAQ.html and
|
2016-05-07 04:49:07 -03:00
|
|
|
https://www.cambridgeincolour.com/tutorials/color-spaces.htm.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The :mod:`colorsys` module defines the following functions:
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: rgb_to_yiq(r, g, b)
|
|
|
|
|
|
|
|
Convert the color from RGB coordinates to YIQ coordinates.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: yiq_to_rgb(y, i, q)
|
|
|
|
|
|
|
|
Convert the color from YIQ coordinates to RGB coordinates.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: rgb_to_hls(r, g, b)
|
|
|
|
|
|
|
|
Convert the color from RGB coordinates to HLS coordinates.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: hls_to_rgb(h, l, s)
|
|
|
|
|
|
|
|
Convert the color from HLS coordinates to RGB coordinates.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: rgb_to_hsv(r, g, b)
|
|
|
|
|
|
|
|
Convert the color from RGB coordinates to HSV coordinates.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: hsv_to_rgb(h, s, v)
|
|
|
|
|
|
|
|
Convert the color from HSV coordinates to RGB coordinates.
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
>>> import colorsys
|
2013-01-11 03:09:07 -04:00
|
|
|
>>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
|
|
|
|
(0.5, 0.5, 0.4)
|
|
|
|
>>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
|
|
|
|
(0.2, 0.4, 0.4)
|