Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`colorsys` --- Conversions between color systems |
| 2 | ===================================================== |
| 3 | |
| 4 | .. module:: colorsys |
| 5 | :synopsis: Conversion functions between RGB and other color systems. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | .. sectionauthor:: David Ascher <da@python.net> |
| 8 | |
Raymond Hettinger | a199368 | 2011-01-27 01:20:32 +0000 | [diff] [blame] | 9 | **Source code:** :source:`Lib/colorsys.py` |
| 10 | |
| 11 | -------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 | |
| 13 | The :mod:`colorsys` module defines bidirectional conversions of color values |
| 14 | between colors expressed in the RGB (Red Green Blue) color space used in |
| 15 | computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness |
| 16 | Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color |
| 17 | spaces are floating point values. In the YIQ space, the Y coordinate is between |
| 18 | 0 and 1, but the I and Q coordinates can be positive or negative. In all other |
| 19 | spaces, the coordinates are all between 0 and 1. |
| 20 | |
Alexandre Vassalotti | 6461e10 | 2008-05-15 22:09:29 +0000 | [diff] [blame] | 21 | .. seealso:: |
| 22 | |
| 23 | More information about color spaces can be found at |
Sanyam Khurana | 338cd83 | 2018-01-20 05:55:37 +0530 | [diff] [blame] | 24 | http://poynton.ca/ColorFAQ.html and |
Serhiy Storchaka | 6dff020 | 2016-05-07 10:49:07 +0300 | [diff] [blame] | 25 | https://www.cambridgeincolour.com/tutorials/color-spaces.htm. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 26 | |
| 27 | The :mod:`colorsys` module defines the following functions: |
| 28 | |
| 29 | |
| 30 | .. function:: rgb_to_yiq(r, g, b) |
| 31 | |
| 32 | Convert the color from RGB coordinates to YIQ coordinates. |
| 33 | |
| 34 | |
| 35 | .. function:: yiq_to_rgb(y, i, q) |
| 36 | |
| 37 | Convert the color from YIQ coordinates to RGB coordinates. |
| 38 | |
| 39 | |
| 40 | .. function:: rgb_to_hls(r, g, b) |
| 41 | |
| 42 | Convert the color from RGB coordinates to HLS coordinates. |
| 43 | |
| 44 | |
| 45 | .. function:: hls_to_rgb(h, l, s) |
| 46 | |
| 47 | Convert the color from HLS coordinates to RGB coordinates. |
| 48 | |
| 49 | |
| 50 | .. function:: rgb_to_hsv(r, g, b) |
| 51 | |
| 52 | Convert the color from RGB coordinates to HSV coordinates. |
| 53 | |
| 54 | |
| 55 | .. function:: hsv_to_rgb(h, s, v) |
| 56 | |
| 57 | Convert the color from HSV coordinates to RGB coordinates. |
| 58 | |
| 59 | Example:: |
| 60 | |
| 61 | >>> import colorsys |
Ezio Melotti | 4050792 | 2013-01-11 09:09:07 +0200 | [diff] [blame] | 62 | >>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4) |
| 63 | (0.5, 0.5, 0.4) |
| 64 | >>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4) |
| 65 | (0.2, 0.4, 0.4) |