Class: Cairo::Color::HSV
Instance Attribute Summary collapse
-
#hue ⇒ Object
(also: #h)
Returns the value of attribute hue.
-
#saturation ⇒ Object
(also: #s)
Returns the value of attribute saturation.
-
#value ⇒ Object
(also: #v)
Returns the value of attribute value.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(h, s, v, a = 1.0) ⇒ HSV
constructor
A new instance of HSV.
- #to_a ⇒ Object (also: #to_ary)
- #to_cmyk ⇒ Object
- #to_hsv ⇒ Object
- #to_rgb ⇒ Object
Constructor Details
#initialize(h, s, v, a = 1.0) ⇒ HSV
Returns a new instance of HSV.
215 216 217 218 219 220 221 222 |
# File 'lib/cairo/color.rb', line 215 def initialize(h, s, v, a=1.0) super(a) assert_in_range(s, "saturation") assert_in_range(v, "value") @hue = h.modulo(360.0) @saturation = s @value = v end |
Instance Attribute Details
#hue ⇒ Object Also known as: h
Returns the value of attribute hue.
206 207 208 |
# File 'lib/cairo/color.rb', line 206 def hue @hue end |
#saturation ⇒ Object Also known as: s
Returns the value of attribute saturation.
206 207 208 |
# File 'lib/cairo/color.rb', line 206 def saturation @saturation end |
#value ⇒ Object Also known as: v
Returns the value of attribute value.
206 207 208 |
# File 'lib/cairo/color.rb', line 206 def value @value end |
Instance Method Details
#to_a ⇒ Object Also known as: to_ary
224 225 226 |
# File 'lib/cairo/color.rb', line 224 def to_a [@hue, @saturation, @value, @alpha] end |
#to_cmyk ⇒ Object
258 259 260 |
# File 'lib/cairo/color.rb', line 258 def to_cmyk to_rgb.to_cmyk end |
#to_hsv ⇒ Object
262 263 264 |
# File 'lib/cairo/color.rb', line 262 def to_hsv clone end |
#to_rgb ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/cairo/color.rb', line 229 def to_rgb if s > 0 h_60 = @hue / 60.0 hi = h_60.floor.modulo(6) f = h_60 - hi p = @value * (1 - @saturation) q = @value * (1 - f * @saturation) t = @value * (1 - (1 - f) * @saturation) case hi when 0 rgb = [@value, t, p] when 1 rgb = [q, @value, p] when 2 rgb = [p, @value, t] when 3 rgb = [p, q, @value] when 4 rgb = [t, p, @value] when 5 rgb = [@value, p, q] end rgba = rgb + [@alpha] RGB.new(*rgba) else RGB.new(@value, @value, @value, @alpha) end end |