Class: ColorMath::HSL
- Inherits:
-
Object
- Object
- ColorMath::HSL
- Includes:
- Color
- Defined in:
- lib/colormath/color/hsl.rb
Overview
A colour represented and stored as hue, saturation and luminance components
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#hue ⇒ Object
readonly
Returns the value of attribute hue.
-
#luminance ⇒ Object
readonly
Returns the value of attribute luminance.
-
#saturation ⇒ Object
readonly
Returns the value of attribute saturation.
Instance Method Summary collapse
-
#blue ⇒ Object
The blue component of the colour in RGB representation where 0 <= b <= 1.
-
#green ⇒ Object
The green component of the colour in RGB representation where 0 <= g <= 1.
-
#initialize(h, s, l) ⇒ HSL
constructor
Initialize an HSL colour where: 0 <= h <= 360 0 <= s <= 1 0 <= l <= 1.
-
#red ⇒ Object
The red component of the colour in RGB representation where 0 <= r <= 1.
Methods included from Color
Constructor Details
#initialize(h, s, l) ⇒ HSL
Initialize an HSL colour where:
0 <= h <= 360
0 <= s <= 1
0 <= l <= 1
Saturation and luminance values outside these ranges will be clipped. Hue values will be mapped to a circle, so that e.g. -20 becomes 340.
18 19 20 21 22 |
# File 'lib/colormath/color/hsl.rb', line 18 def initialize(h, s, l) @hue = h % 360 @saturation = force_range(s, 0, 1).to_f @luminance = force_range(l, 0, 1).to_f end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
8 9 10 |
# File 'lib/colormath/color/hsl.rb', line 8 def alpha @alpha end |
#hue ⇒ Object (readonly)
Returns the value of attribute hue.
8 9 10 |
# File 'lib/colormath/color/hsl.rb', line 8 def hue @hue end |
#luminance ⇒ Object (readonly)
Returns the value of attribute luminance.
8 9 10 |
# File 'lib/colormath/color/hsl.rb', line 8 def luminance @luminance end |
#saturation ⇒ Object (readonly)
Returns the value of attribute saturation.
8 9 10 |
# File 'lib/colormath/color/hsl.rb', line 8 def saturation @saturation end |
Instance Method Details
#blue ⇒ Object
The blue component of the colour in RGB representation where 0 <= b <= 1
38 39 40 |
# File 'lib/colormath/color/hsl.rb', line 38 def blue t = component(hk - (1/3.0)) end |
#green ⇒ Object
The green component of the colour in RGB representation where 0 <= g <= 1
32 33 34 |
# File 'lib/colormath/color/hsl.rb', line 32 def green t = component(hk) end |
#red ⇒ Object
The red component of the colour in RGB representation where 0 <= r <= 1
26 27 28 |
# File 'lib/colormath/color/hsl.rb', line 26 def red t = component(hk + (1/3.0)) end |