# 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
# File lib/cairo/color.rb, line 224 def to_a [@hue, @saturation, @value, @alpha] end
# File lib/cairo/color.rb, line 258 def to_cmyk to_rgb.to_cmyk end
# File lib/cairo/color.rb, line 262 def to_hsv clone end
# 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