-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGB.rb
More file actions
28 lines (23 loc) · 704 Bytes
/
RGB.rb
File metadata and controls
28 lines (23 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require './Triplet.rb'
class RGB < Triplet
[[:r, :x], [:g, :y], [:b, :z]].each{|ar|
eval("alias #{ar[0]} #{ar[1]}")
eval("alias #{ar[0]}= #{ar[1]}=")
}
def initialize(x = 0.0, y = nil, z = nil, color_level = 256)
@color_level = color_level
super(x, y, z)
end
undef_method(:join)
def to_s
[@x, @y, @z].map{ ((@color_level - 0.001) * _1).to_i }.reduce{|result, pt| result.to_s + ' ' + pt.to_s }
end
def to_trpl
Triplet.new((@color_level - 0.001) * @x,
(@color_level - 0.001) * @y,
(@color_level - 0.001) * @z)
end
end
def rgb(r = 0.0, g = nil, b = nil)
RGB.new(r, g, b)
end