“Python/docs/3.9/library/colorsys”的版本间差异

来自菜鸟教程
Python/docs/3.9/library/colorsys
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:colorsys — 颜色系统之间的转换 — Python 文档}}
 
<div id="module-colorsys" class="section">
 
<div id="module-colorsys" class="section">
  
 
<span id="colorsys-conversions-between-color-systems"></span>
 
<span id="colorsys-conversions-between-color-systems"></span>
= [[#module-colorsys|<code>colorsys</code>]] --- Conversions between color systems =
+
= colorsys — 颜色系统之间的转换 =
  
'''Source code:''' [https://github.com/python/cpython/tree/3.9/Lib/colorsys.py Lib/colorsys.py]
+
'''源代码:''' [[#id1|<span id="id2" class="problematic">:source:`Lib/colorsys.py`</span>]]
  
The [[#module-colorsys|<code>colorsys</code>]] 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
+
[[#module-colorsys|colorsys]] 模块定义了在计算机显示器中使用的 RGB(红绿蓝)颜色空间和其他三个坐标系中表示的颜色之间颜色值的双向转换:YIQ、HLS(色相亮度饱和度)和 HSV(色相饱和度)饱和值)。 所有这些颜色空间中的坐标都是浮点值。 在 YIQ 空间中,Y 坐标在 0 1 之间,但 I Q 坐标可以为正也可以为负。 在所有其他空间中,坐标都在 0 1 之间。
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.
 
  
 
<div class="admonition seealso">
 
<div class="admonition seealso">
  
参见
+
也可以看看
  
More information about color spaces can be found at
+
有关色彩空间的更多信息,请访问 https://poynton.ca/ColorFAQ.html https://www.cambridgeincolour.com/tutorials/color-spaces.htm .
https://poynton.ca/ColorFAQ.html and
 
https://www.cambridgeincolour.com/tutorials/color-spaces.htm.
 
  
  
 
</div>
 
</div>
The [[#module-colorsys|<code>colorsys</code>]] module defines the following functions:
+
[[#module-colorsys|colorsys]] 模块定义了以下函数:
  
; <code>colorsys.</code><code>rgb_to_yiq</code><span class="sig-paren">(</span>''<span class="n">r</span>'', ''<span class="n">g</span>'', ''<span class="n">b</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_yiq</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span>
: Convert the color from RGB coordinates to YIQ coordinates.
+
: 将颜色从 RGB 坐标转换为 YIQ 坐标。
  
; <code>colorsys.</code><code>yiq_to_rgb</code><span class="sig-paren">(</span>''<span class="n">y</span>'', ''<span class="n">i</span>'', ''<span class="n">q</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">yiq_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">y</span></span>'', ''<span class="n"><span class="pre">i</span></span>'', ''<span class="n"><span class="pre">q</span></span>''<span class="sig-paren">)</span>
: Convert the color from YIQ coordinates to RGB coordinates.
+
: 将颜色从 YIQ 坐标转换为 RGB 坐标。
  
; <code>colorsys.</code><code>rgb_to_hls</code><span class="sig-paren">(</span>''<span class="n">r</span>'', ''<span class="n">g</span>'', ''<span class="n">b</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_hls</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span>
: Convert the color from RGB coordinates to HLS coordinates.
+
: 将颜色从 RGB 坐标转换为 HLS 坐标。
  
; <code>colorsys.</code><code>hls_to_rgb</code><span class="sig-paren">(</span>''<span class="n">h</span>'', ''<span class="n">l</span>'', ''<span class="n">s</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">hls_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">h</span></span>'', ''<span class="n"><span class="pre">l</span></span>'', ''<span class="n"><span class="pre">s</span></span>''<span class="sig-paren">)</span>
: Convert the color from HLS coordinates to RGB coordinates.
+
: 将颜色从 HLS 坐标转换为 RGB 坐标。
  
; <code>colorsys.</code><code>rgb_to_hsv</code><span class="sig-paren">(</span>''<span class="n">r</span>'', ''<span class="n">g</span>'', ''<span class="n">b</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_hsv</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span>
: Convert the color from RGB coordinates to HSV coordinates.
+
: 将颜色从 RGB 坐标转换为 HSV 坐标。
  
; <code>colorsys.</code><code>hsv_to_rgb</code><span class="sig-paren">(</span>''<span class="n">h</span>'', ''<span class="n">s</span>'', ''<span class="n">v</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">hsv_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">h</span></span>'', ''<span class="n"><span class="pre">s</span></span>'', ''<span class="n"><span class="pre">v</span></span>''<span class="sig-paren">)</span>
: Convert the color from HSV coordinates to RGB coordinates.
+
: 将颜色从 HSV 坐标转换为 RGB 坐标。
  
Example:
+
例子:
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第50行: 第46行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; import colorsys
+
<syntaxhighlight lang="python3">>>> import colorsys
&gt;&gt;&gt; colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
+
>>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
 
(0.5, 0.5, 0.4)
 
(0.5, 0.5, 0.4)
&gt;&gt;&gt; colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
+
>>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
(0.2, 0.4, 0.4)</pre>
+
(0.2, 0.4, 0.4)</syntaxhighlight>
 +
 
 +
</div>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
 +
<div class="clearer">
 +
 +
  
 
</div>
 
</div>
  
[[Category:Python 3.9 中文文档]]
+
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:51的最新版本

colorsys — 颜色系统之间的转换

源代码: :source:`Lib/colorsys.py`



colorsys 模块定义了在计算机显示器中使用的 RGB(红绿蓝)颜色空间和其他三个坐标系中表示的颜色之间颜色值的双向转换:YIQ、HLS(色相亮度饱和度)和 HSV(色相饱和度)饱和值)。 所有这些颜色空间中的坐标都是浮点值。 在 YIQ 空间中,Y 坐标在 0 和 1 之间,但 I 和 Q 坐标可以为正也可以为负。 在所有其他空间中,坐标都在 0 和 1 之间。

也可以看看

有关色彩空间的更多信息,请访问 https://poynton.ca/ColorFAQ.htmlhttps://www.cambridgeincolour.com/tutorials/color-spaces.htm .


colorsys 模块定义了以下函数:

colorsys.rgb_to_yiq(r, g, b)
将颜色从 RGB 坐标转换为 YIQ 坐标。
colorsys.yiq_to_rgb(y, i, q)
将颜色从 YIQ 坐标转换为 RGB 坐标。
colorsys.rgb_to_hls(r, g, b)
将颜色从 RGB 坐标转换为 HLS 坐标。
colorsys.hls_to_rgb(h, l, s)
将颜色从 HLS 坐标转换为 RGB 坐标。
colorsys.rgb_to_hsv(r, g, b)
将颜色从 RGB 坐标转换为 HSV 坐标。
colorsys.hsv_to_rgb(h, s, v)
将颜色从 HSV 坐标转换为 RGB 坐标。

例子:

>>> import colorsys
>>> 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)