Class: Savio::RgbColor
- Inherits:
-
Struct
- Object
- Struct
- Savio::RgbColor
- Defined in:
- lib/savio/hsv2rgb.rb
Instance Attribute Summary collapse
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#b ⇒ Object
Returns the value of attribute b
2 3 4 |
# File 'lib/savio/hsv2rgb.rb', line 2 def b @b end |
#g ⇒ Object
Returns the value of attribute g
2 3 4 |
# File 'lib/savio/hsv2rgb.rb', line 2 def g @g end |
#r ⇒ Object
Returns the value of attribute r
2 3 4 |
# File 'lib/savio/hsv2rgb.rb', line 2 def r @r end |
Class Method Details
.newFromHSV(hsv) ⇒ Object
3 4 5 6 |
# File 'lib/savio/hsv2rgb.rb', line 3 def self.newFromHSV(hsv) rgb = hsv.to_rgb() return RgbColor.new(rgb.r,rgb.g,rgb.b) end |
Instance Method Details
#to_hsv ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/savio/hsv2rgb.rb', line 7 def to_hsv() max = [r, g, b].max min = [r, g, b].min delta = max - min v = max if (max != 0.0) s = delta / max else s = 0.0 end if (s == 0.0) h = 0.0 else if (r == max) h = 0 + (g - b) / delta elsif (g == max) h = 2 + (b - r) / delta elsif (b == max) h = 4 + (r - g) / delta end h *= 60.0 if (h < 0) h += 360.0 end end return HsvColor.new(h,s,v) end |