colour.conversions.hsl2rgb

colour.conversions.hsl2rgb(hsl: Tuple[float, float, float]) Tuple[float, float, float]

Convert HSL representation towards RGB.

Parameters
  • h – Hue, position around the chromatic circle (h=1 equiv h=0)

  • s – Saturation, color saturation (0=full gray, 1=full color)

  • l – Ligthness, Overhaul lightness (0=full black, 1=full white)

Return type

3-uple for RGB values in float between 0 and 1

Hue, Saturation, Range from Lightness is a float between 0 and 1

Note that Hue can be set to any value but as it is a rotation around the chromatic circle, any value above 1 or below 0 can be expressed by a value between 0 and 1 (Note that h=0 is equiv to h=1).

This algorithm came from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19

Here are some quick notion of HSL to RGB conversion:

>>> from colour import hsl2rgb

With a lightness put at 0, RGB is always rgbblack

>>> hsl2rgb((0.0, 0.0, 0.0))
(0.0, 0.0, 0.0)
>>> hsl2rgb((0.5, 0.0, 0.0))
(0.0, 0.0, 0.0)
>>> hsl2rgb((0.5, 0.5, 0.0))
(0.0, 0.0, 0.0)

Same for lightness put at 1, RGB is always rgbwhite

>>> hsl2rgb((0.0, 0.0, 1.0))
(1.0, 1.0, 1.0)
>>> hsl2rgb((0.5, 0.0, 1.0))
(1.0, 1.0, 1.0)
>>> hsl2rgb((0.5, 0.5, 1.0))
(1.0, 1.0, 1.0)

With saturation put at 0, the RGB should be equal to Lightness:

>>> hsl2rgb((0.0, 0.0, 0.25))
(0.25, 0.25, 0.25)
>>> hsl2rgb((0.5, 0.0, 0.5))
(0.5, 0.5, 0.5)
>>> hsl2rgb((0.5, 0.0, 0.75))
(0.75, 0.75, 0.75)

With saturation put at 1, and lightness put to 0.5, we can find normal full red, green, blue colors:

>>> hsl2rgb((0 , 1.0, 0.5))
(1.0, 0.0, 0.0)
>>> hsl2rgb((1 , 1.0, 0.5))
(1.0, 0.0, 0.0)
>>> hsl2rgb((1.0/3 , 1.0, 0.5))
(0.0, 1.0, 0.0)
>>> hsl2rgb((2.0/3 , 1.0, 0.5))
(0.0, 0.0, 1.0)

Of course: >>> hsl2rgb((0.0, 2.0, 0.5)) # doctest: +ELLIPSIS Traceback (most recent call last): … ValueError: Saturation must be between 0 and 1.

And: >>> hsl2rgb((0.0, 0.0, 1.5)) # doctest: +ELLIPSIS Traceback (most recent call last): … ValueError: Lightness must be between 0 and 1.