Sha256: 07903631ddadee1dffa2de6ce7fb970d5f5c9c68bd6ee5b7e365051384afbff2
Contents?: true
Size: 730 Bytes
Versions: 1
Compression:
Stored size: 730 Bytes
Contents
# Hue Saturation and Value. Hue can range from [0,360). Saturation and # Value are [0,1] class HSV attr_accessor :h, :s, :v include Colour 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 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 def to_cmyk self.to_rgb.to_cmyk end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
colour-0.4.0 | lib/hsv.rb |