Class: Color::XYZ

Inherits:
Object
  • Object
show all
Defined in:
lib/color/xyz.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ XYZ

Returns a new instance of XYZ.



10
11
12
13
14
# File 'lib/color/xyz.rb', line 10

def initialize(color)
  @r = color.r.to_f
  @g = color.g.to_f
  @b = color.b.to_f
end

Instance Attribute Details

#bObject (readonly)

Returns the value of attribute b.



4
5
6
# File 'lib/color/xyz.rb', line 4

def b
  @b
end

#gObject (readonly)

Returns the value of attribute g.



4
5
6
# File 'lib/color/xyz.rb', line 4

def g
  @g
end

#rObject (readonly)

Returns the value of attribute r.



4
5
6
# File 'lib/color/xyz.rb', line 4

def r
  @r
end

Class Method Details

.from_rgb(rgb_color) ⇒ Object



6
7
8
# File 'lib/color/xyz.rb', line 6

def self.from_rgb(rgb_color)
  self.new(rgb_color)
end

Instance Method Details

#convert(value) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/color/xyz.rb', line 44

def convert(value)
  variable = (send(value) / 255.0)
  if ( variable > 0.04045)
    variable = ( ( variable + 0.055) / 1.055) ** 2.4
  else
    variable = variable / 12.92
  end
  variable * 100
end

#to_aObject



16
17
18
# File 'lib/color/xyz.rb', line 16

def to_a
  [x, y, z]
end

#var_bObject



40
41
42
# File 'lib/color/xyz.rb', line 40

def var_b
  @var_b ||= convert(:b)
end

#var_gObject



36
37
38
# File 'lib/color/xyz.rb', line 36

def var_g
  @var_g ||= convert(:g)
end

#var_rObject



32
33
34
# File 'lib/color/xyz.rb', line 32

def var_r
  @var_r ||= convert(:r)
end

#xObject



20
21
22
# File 'lib/color/xyz.rb', line 20

def x
  @x ||= ( var_r * 0.4124 + var_g * 0.3576 + var_b * 0.1805 )
end

#yObject



24
25
26
# File 'lib/color/xyz.rb', line 24

def y
  @y ||= ( var_r * 0.2126 + var_g * 0.7152 + var_b * 0.0722)
end

#zObject



28
29
30
# File 'lib/color/xyz.rb', line 28

def z
  @z ||= ( var_r * 0.0193 + var_g * 0.1192 + var_b * 0.9505)
end