Class: HSV
Overview
Hue Saturation and Value. Hue can range from [0,360). Saturation and Value are [0,1]
Instance Attribute Summary collapse
-
#h ⇒ Object
Returns the value of attribute h.
-
#s ⇒ Object
Returns the value of attribute s.
-
#v ⇒ Object
Returns the value of attribute v.
Instance Method Summary collapse
-
#initialize(h = 0.0, s = 0.0, v = 0.0) ⇒ HSV
constructor
A new instance of HSV.
- #to_cmyk ⇒ Object
- #to_rgb ⇒ Object
Methods included from Colour
#analogous, #complementary, #gradient_to, #hex, #rotate_hue, #split_complementary, #to_hsv, #to_s, #triadic, #web_hex, #web_safe
Constructor Details
#initialize(h = 0.0, s = 0.0, v = 0.0) ⇒ HSV
Returns a new instance of HSV.
8 9 10 11 12 |
# File 'lib/hsv.rb', line 8 def initialize(h=0.0, s=0.0, v=0.0) @h = h.abs.to_f % 360 @s = s.abs.to_f @v = v.abs.to_f end |
Instance Attribute Details
#h ⇒ Object
Returns the value of attribute h.
5 6 7 |
# File 'lib/hsv.rb', line 5 def h @h end |
#s ⇒ Object
Returns the value of attribute s.
5 6 7 |
# File 'lib/hsv.rb', line 5 def s @s end |
#v ⇒ Object
Returns the value of attribute v.
5 6 7 |
# File 'lib/hsv.rb', line 5 def v @v end |
Instance Method Details
#to_cmyk ⇒ Object
41 42 43 |
# File 'lib/hsv.rb', line 41 def to_cmyk self.to_rgb.to_cmyk end |
#to_rgb ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hsv.rb', line 14 def to_rgb if (@s == 0) then #Shade of grey RGB.new(@v, @v, @v) else @h /= 60 i = @h.floor f = @h - i p = @v * (1 - @s) q = @v * (1 - @s * f) t = @v * (1 - @s * (1 - f)) case i when 0 then RGB.new(v,t,p) when 1 then RGB.new(q,v,p) when 2 then RGB.new(p,v,t) when 3 then RGB.new(p,q,v) when 4 then RGB.new(t,p,v) else RGB.new(v,p,q) end end end |