Class: Color::CIELab

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ CIELab

Returns a new instance of CIELab.



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

def initialize(color)
  @x = color.x
  @y = color.y
  @z = color.z
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

#zObject (readonly)

Returns the value of attribute z.



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

def z
  @z
end

Class Method Details

.from_xyz(xyz_color) ⇒ Object



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

def self.from_xyz(xyz_color)
  self.new(xyz_color)
end

Instance Method Details

#aObject



48
49
50
# File 'lib/color/cie_lab.rb', line 48

def a
  500.0 * ( var_x - var_y)
end

#bObject



52
53
54
# File 'lib/color/cie_lab.rb', line 52

def b
  200.0 * ( var_y - var_z)
end

#lObject



44
45
46
# File 'lib/color/cie_lab.rb', line 44

def l
  ( 116.0 * var_y) - 16.0
end

#reference_xObject



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

def reference_x
  95.047 # Observer= 2°, Illuminant= D65
end

#reference_yObject



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

def reference_y
  100.00
end

#reference_zObject



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

def reference_z
  108.883
end

#to_aObject



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

def to_a
  [l, a, b]
end

#var_xObject



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

def var_x
  @var_x ||= calculate_var(x / reference_x)
end

#var_yObject



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

def var_y
  @var_y ||= calculate_var(y / reference_y)
end

#var_zObject



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

def var_z
  @var_z ||= calculate_var(z / reference_z)
end