summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fcolorsys.html
blob: ed442b599f72fecf10c9a421c993f11c48ddd27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 <span id="colorsys-conversions-between-color-systems"></span><h1>colorsys — Conversions between color systems</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/colorsys.py">Lib/colorsys.py</a></p>  <p>The <a class="reference internal" href="#module-colorsys" title="colorsys: Conversion functions between RGB and other color systems."><code>colorsys</code></a> 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.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p>More information about color spaces can be found at <a class="reference external" href="https://poynton.ca/ColorFAQ.html">https://poynton.ca/ColorFAQ.html</a> and <a class="reference external" href="https://www.cambridgeincolour.com/tutorials/color-spaces.htm">https://www.cambridgeincolour.com/tutorials/color-spaces.htm</a>.</p> </div> <p>The <a class="reference internal" href="#module-colorsys" title="colorsys: Conversion functions between RGB and other color systems."><code>colorsys</code></a> module defines the following functions:</p> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.rgb_to_yiq">
<code>colorsys.rgb_to_yiq(r, g, b)</code> </dt> <dd>
<p>Convert the color from RGB coordinates to YIQ coordinates.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.yiq_to_rgb">
<code>colorsys.yiq_to_rgb(y, i, q)</code> </dt> <dd>
<p>Convert the color from YIQ coordinates to RGB coordinates.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.rgb_to_hls">
<code>colorsys.rgb_to_hls(r, g, b)</code> </dt> <dd>
<p>Convert the color from RGB coordinates to HLS coordinates.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.hls_to_rgb">
<code>colorsys.hls_to_rgb(h, l, s)</code> </dt> <dd>
<p>Convert the color from HLS coordinates to RGB coordinates.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.rgb_to_hsv">
<code>colorsys.rgb_to_hsv(r, g, b)</code> </dt> <dd>
<p>Convert the color from RGB coordinates to HSV coordinates.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="colorsys.hsv_to_rgb">
<code>colorsys.hsv_to_rgb(h, s, v)</code> </dt> <dd>
<p>Convert the color from HSV coordinates to RGB coordinates.</p> </dd>
</dl> <p>Example:</p> <pre data-language="python">&gt;&gt;&gt; import colorsys
&gt;&gt;&gt; colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
(0.5, 0.5, 0.4)
&gt;&gt;&gt; colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
(0.2, 0.4, 0.4)
</pre> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
    <a href="https://docs.python.org/3.12/library/colorsys.html" class="_attribution-link">https://docs.python.org/3.12/library/colorsys.html</a>
  </p>
</div>