class Cairo::Color::RGB
Attributes
b[RW]
b=[RW]
blue[RW]
g[RW]
g=[RW]
green[RW]
r[RW]
r=[RW]
red[RW]
Public Class Methods
new(r, g, b, a=1.0)
click to toggle source
Calls superclass method
Cairo::Color::Base::new
# File lib/cairo/color.rb, line 81 def initialize(r, g, b, a=1.0) super(a) assert_in_range(r, "red") assert_in_range(g, "green") assert_in_range(b, "blue") @red = r @green = g @blue = b end
Public Instance Methods
==(other)
click to toggle source
# File lib/cairo/color.rb, line 99 def ==(other) other.is_a?(self.class) and other.to_s == to_s end
eql?(other)
click to toggle source
# File lib/cairo/color.rb, line 95 def eql?(other) self == other end
hash()
click to toggle source
# File lib/cairo/color.rb, line 91 def hash to_s.hash end
to_a()
click to toggle source
# File lib/cairo/color.rb, line 103 def to_a [@red, @green, @blue, @alpha] end
Also aliased as: to_ary
to_cmyk()
click to toggle source
# File lib/cairo/color.rb, line 116 def to_cmyk cmy = [1.0 - @red, 1.0 - @green, 1.0 - @blue] key_plate = cmy.min if key_plate < 1.0 one_k = 1.0 - key_plate cmyk = cmy.collect {|value| (value - key_plate) / one_k} + [key_plate] else cmyk = [0, 0, 0, key_plate] end cmyka = cmyk + [@alpha] CMYK.new(*cmyka) end
to_hsv()
click to toggle source
# File lib/cairo/color.rb, line 129 def to_hsv max = [@red, @blue, @green].max if max > 0 min = [@red, @blue, @green].min max_min = max - min case max when @red numerator = @green - @blue angle = 0 when @green numerator = @blue - @red angle = 120 when @blue numerator = @red - @green angle = 240 end h = max_min > 0 ? 60 * numerator / max_min + angle : 0.0 s = max_min / max else h = 0.0 s = 0.0 end v = max HSV.new(h, s, v, @alpha) end
to_rgb()
click to toggle source
# File lib/cairo/color.rb, line 112 def to_rgb clone end
to_s()
click to toggle source
# File lib/cairo/color.rb, line 108 def to_s "#%02X%02X%02X%02X" % to_a.collect {|v| (v * 255).round(1)} end