Class: Hue::Colors::XY
Constant Summary collapse
- MIN =
0.0
- MAX =
1.0
- RGB_MATRIX =
Matrix[ [ 3.233358361244897, -1.5262682428425947, 0.27916711262124544]
Constants inherited from Color
Color::ERROR_METHOD_NOT_IMPLEMENTED
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(*xy) ⇒ XY
constructor
A new instance of XY.
- #to_hash ⇒ Object
- #to_rgb ⇒ Object
- #to_s ⇒ Object
Methods inherited from Color
Constructor Details
#initialize(*xy) ⇒ XY
Returns a new instance of XY.
18 19 20 21 |
# File 'lib/hue/colors/xy.rb', line 18 def initialize(*xy) self.x = xy.first self.y = xy.last end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
16 17 18 |
# File 'lib/hue/colors/xy.rb', line 16 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
16 17 18 |
# File 'lib/hue/colors/xy.rb', line 16 def y @y end |
Instance Method Details
#to_hash ⇒ Object
31 32 33 |
# File 'lib/hue/colors/xy.rb', line 31 def to_hash {xy: xy} end |
#to_rgb ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/hue/colors/xy.rb', line 39 def to_rgb z = 1 - x - y xyz = [x, y, z] values = (RGB_MATRIX * Matrix[xyz].transpose).to_a.flatten.map do |x| RGB.ranged(x * RGB::MAX).to_i end RGB.new(*values) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/hue/colors/xy.rb', line 35 def to_s "XY=#{xy}" end |