Class: Colors::HSL
- Inherits:
-
AbstractColor
- Object
- AbstractColor
- Colors::HSL
- Includes:
- Helper
- Defined in:
- lib/colors/hsl.rb
Instance Attribute Summary collapse
-
#h ⇒ Object
(also: #hue)
Returns the value of attribute h.
-
#l ⇒ Object
(also: #lightness)
Returns the value of attribute l.
-
#s ⇒ Object
(also: #saturation)
Returns the value of attribute s.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #components ⇒ Object (also: #hsl_components)
- #desaturate(factor) ⇒ Object
-
#initialize(h, s, l) ⇒ HSL
constructor
A new instance of HSL.
- #rgb_components ⇒ Object
- #to_hsl ⇒ Object
- #to_hsla(alpha: 1.0) ⇒ Object
- #to_rgb ⇒ Object
- #to_rgba(alpha: 1.0) ⇒ Object
Methods inherited from AbstractColor
Constructor Details
#initialize(h, s, l) ⇒ HSL
Returns a new instance of HSL.
5 6 7 |
# File 'lib/colors/hsl.rb', line 5 def initialize(h, s, l) @h, @s, @l = canonicalize(h, s, l) end |
Instance Attribute Details
#h ⇒ Object Also known as: hue
Returns the value of attribute h.
9 10 11 |
# File 'lib/colors/hsl.rb', line 9 def h @h end |
#l ⇒ Object Also known as: lightness
Returns the value of attribute l.
9 10 11 |
# File 'lib/colors/hsl.rb', line 9 def l @l end |
#s ⇒ Object Also known as: saturation
Returns the value of attribute s.
9 10 11 |
# File 'lib/colors/hsl.rb', line 9 def s @s end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/colors/hsl.rb', line 45 def ==(other) case other when HSLA other == self when HSL h == other.h && s == other.s && l == other.l else super end end |
#components ⇒ Object Also known as: hsl_components
11 12 13 |
# File 'lib/colors/hsl.rb', line 11 def components [h, s, l] end |
#desaturate(factor) ⇒ Object
56 57 58 |
# File 'lib/colors/hsl.rb', line 56 def desaturate(factor) HSL.new(h, s*factor, l) end |
#rgb_components ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/colors/hsl.rb', line 78 def rgb_components t2 = if l <= 0.5r l * (s + 1r) else l + s - l * s end t1 = l * 2r - t2 hh = h/60r r = hue_to_rgb(t1, t2, hh + 2) g = hue_to_rgb(t1, t2, hh) b = hue_to_rgb(t1, t2, hh - 2) [r, g, b] end |
#to_hsl ⇒ Object
60 61 62 |
# File 'lib/colors/hsl.rb', line 60 def to_hsl self end |
#to_hsla(alpha: 1.0) ⇒ Object
64 65 66 67 |
# File 'lib/colors/hsl.rb', line 64 def to_hsla(alpha: 1.0) alpha = canonicalize_component(alpha, :alpha) HSLA.new(h, s, l, alpha) end |