/Doc/library/colorsys.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 61 lines · 35 code · 26 blank · 0 comment · 0 complexity · 1907fa82b8db33a5fbcb74ea97f553c4 MD5 · raw file

  1. :mod:`colorsys` --- Conversions between color systems
  2. =====================================================
  3. .. module:: colorsys
  4. :synopsis: Conversion functions between RGB and other color systems.
  5. .. sectionauthor:: David Ascher <da@python.net>
  6. The :mod:`colorsys` module defines bidirectional conversions of color values
  7. between colors expressed in the RGB (Red Green Blue) color space used in
  8. computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness
  9. Saturation) and HSV (Hue Saturation Value). Coordinates in all of these color
  10. spaces are floating point values. In the YIQ space, the Y coordinate is between
  11. 0 and 1, but the I and Q coordinates can be positive or negative. In all other
  12. spaces, the coordinates are all between 0 and 1.
  13. .. seealso::
  14. More information about color spaces can be found at
  15. http://www.poynton.com/ColorFAQ.html and
  16. http://www.cambridgeincolour.com/tutorials/color-spaces.htm.
  17. The :mod:`colorsys` module defines the following functions:
  18. .. function:: rgb_to_yiq(r, g, b)
  19. Convert the color from RGB coordinates to YIQ coordinates.
  20. .. function:: yiq_to_rgb(y, i, q)
  21. Convert the color from YIQ coordinates to RGB coordinates.
  22. .. function:: rgb_to_hls(r, g, b)
  23. Convert the color from RGB coordinates to HLS coordinates.
  24. .. function:: hls_to_rgb(h, l, s)
  25. Convert the color from HLS coordinates to RGB coordinates.
  26. .. function:: rgb_to_hsv(r, g, b)
  27. Convert the color from RGB coordinates to HSV coordinates.
  28. .. function:: hsv_to_rgb(h, s, v)
  29. Convert the color from HSV coordinates to RGB coordinates.
  30. Example::
  31. >>> import colorsys
  32. >>> colorsys.rgb_to_hsv(.3, .4, .2)
  33. (0.25, 0.5, 0.4)
  34. >>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4)
  35. (0.3, 0.4, 0.2)