1Convert::Color::HSL(3)User Contributed Perl DocumentationConvert::Color::HSL(3)
2
3
4
6 "Convert::Color::HSL" - a color value represented as
7 hue/saturation/lightness
8
10 Directly:
11
12 use Convert::Color::HSL;
13
14 my $red = Convert::Color::HSL->new( 0, 1, 0.5 );
15
16 # Can also parse strings
17 my $pink = Convert::Color::HSL->new( '0,1,0.8' );
18
19 Via Convert::Color:
20
21 use Convert::Color;
22
23 my $cyan = Convert::Color->new( 'hsl:300,1,0.5' );
24
26 Objects in this class represent a color in HSL space, as a set of three
27 floating-point values. Hue is stored as a value in degrees, in the
28 range 0 to 360 (exclusive). Saturation and lightness are in the range 0
29 to 1.
30
31 This color space may be considered as a cylinder, of height and radius
32 1. Hue represents the position of the color as the angle around the
33 axis, the saturation as the distance from the axis, and the lightness
34 the height above the base. In this shape, the entire base of the
35 cylinder is pure black, the axis through the centre represents the
36 range of greys, and the entire top of the cylinder is pure white. The
37 circumference of the circular cross-section midway along the axis
38 contains the pure-saturated color wheel.
39
40 Because both surfaces of this cylinder contain pure black or white
41 discs, a closely-related color space can be created by reshaping the
42 cylinder into a bi-cone such that the top and bottom of the cylinder
43 become single points. The radius from the axis of this shape is called
44 the chroma (though this is a different definition of "chroma" than that
45 used by CIE).
46
47 While the components of this space are called Hue-Chroma-Lightness, it
48 should not be confused with the similarly-named Hue-Chroma-Luminance
49 (HCL) space.
50
52 $color = Convert::Color::HSL->new( $hue, $saturation, $lightness )
53 Returns a new object to represent the set of values given. The hue
54 should be in the range 0 to 360 (exclusive), and saturation and
55 lightness should be between 0 and 1. Values outside of these ranges
56 will be clamped.
57
58 $color = Convert::Color::HSL->new( $string )
59 Parses $string for values, and construct a new object similar to the
60 above three-argument form. The string should be in the form
61
62 hue,saturation,lightnes
63
64 containing the three floating-point values in decimal notation.
65
67 $h = $color->hue
68 $s = $color->saturation
69 $v = $color->lightness
70 Accessors for the three components of the color.
71
72 $c = $color->chroma
73 Returns the derived property of "chroma", which maps the color space
74 onto a bicone instead of a cylinder. This more closely measures the
75 intuitive concept of how "colorful" the color is than the saturation
76 value and is useful for distance calculations.
77
78 ( $hue, $saturation, $lightness ) = $color->hsl
79 Returns the individual hue, saturation and lightness components of the
80 color value.
81
82 $measure = $color->dst_hsl( $other )
83 Returns a measure of the distance between the two colors. This is the
84 Euclidean distance between the two colors as points in the chroma-
85 adjusted cone space.
86
87 $measure = $color->dst_hsl_cheap( $other )
88 Returns a measure of the distance between the two colors. This is used
89 in the calculation of "dst_hsl" but since it omits the final square-
90 root and scaling it is cheaper to calculate, for use in cases where
91 only the relative values matter, such as when picking the "best match"
92 out of a set of colors. It ranges between 0 for identical colors and 4
93 for the distance between complementary pure-saturated colors.
94
96 • Convert::Color - color space conversions
97
98 • Convert::Color::RGB - a color value represented as red/green/blue
99
100 • <http://en.wikipedia.org/wiki/HSL_and_HSV> - HSL and HSV on
101 Wikipedia
102
104 Paul Evans <leonerd@leonerd.org.uk>
105
106
107
108perl v5.32.1 2021-01-27 Convert::Color::HSL(3)