HSL¶
import introcs
This class represents an HSL color value. As an additive color, it has conversion
methods for tkinter
, kivy
and PIL
. However, most of these methods require
conversion to RGB color space before use.
HSL colors are represented by a double cone. Pure color values such as red or green
are positioned at the vertical center of the cone, with a lightness
value of 0.5.
Constructor¶
- class introcs.HSL(h, s, l)¶
An instance is a HSL color value.
The
hue
range is not inclusive on the high end. So 359.99999 is a valid hue, but 360.0 is not. All other color values are inclusive.- Parameters
h (
float
0.0..360.0, not including 360.0) – the initial hues (
float
0.0..1.0) – the initial saturationl (
float
0.0..1.0) – the initial lightness
Attributes¶
- HSL.hue¶
The hue channel.
Invariant: Value must be a float between 0.0 and 360.0, not including 360.0.
- HSL.saturation¶
The staturation channel.
Invariant: Value must be a float between 0.0 and 1.0, inclusive.
- HSL.lightness¶
The lightness channel.
Invariant: Lightness must be a float between 0.0 and 1.0, inclusive.
Methods¶
- HSL.glColor()¶
Converts thie color to an OpenGL value.
This conversion allows this object to be used by graphics libraries that depend on OpenGL (e.g. Kivy). The conversion first converts this object to the RGB color space.
- Returns
a 4 element list of the attributes in the range 0 to 1
- Return type
list
- HSL.webColor()¶
Converts this color to a web color string.
This conversion allows this object to be used by graphics libraries that depend on Tkinter (e.g. the drawing turtle). The conversion first converts this object to the RGB color space.
- Returns
a string representing a web color
- Return type
str
- HSL.rgba()¶
Converts this color to an rgba value.
This conversion allows this object to be used by graphics libraries that want integer color representation like PIL. The conversion first converts this object to the RGB color space.
- Returns
a 4 element tuple of the attributes in the range 0 to 255
- Return type
tuple