Class: Hue::Colors::XY

Inherits:
Color
  • Object
show all
Defined in:
lib/hue/colors/xy.rb

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

Instance Method Summary collapse

Methods inherited from Color

ranged

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

#xObject

Returns the value of attribute x.



16
17
18
# File 'lib/hue/colors/xy.rb', line 16

def x
  @x
end

#yObject

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_hashObject



31
32
33
# File 'lib/hue/colors/xy.rb', line 31

def to_hash
  {xy: xy}
end

#to_rgbObject



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_sObject



35
36
37
# File 'lib/hue/colors/xy.rb', line 35

def to_s
  "XY=#{xy}"
end