Class: Tco::Colour

Inherits:
Object
  • Object
show all
Defined in:
lib/tco/palette.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rgb, lab = nil) ⇒ Colour

Returns a new instance of Colour.



40
41
42
43
44
45
# File 'lib/tco/palette.rb', line 40

def initialize(rgb, lab=nil)
  @rgb = rgb
  @lab = lab ? lab : rgb_to_lab(rgb)
  @hsl = nil
  @yiq = nil
end

Instance Attribute Details

#labObject (readonly)

Returns the value of attribute lab.



38
39
40
# File 'lib/tco/palette.rb', line 38

def lab
  @lab
end

#rgbObject (readonly)

Returns the value of attribute rgb.



38
39
40
# File 'lib/tco/palette.rb', line 38

def rgb
  @rgb
end

Instance Method Details

#-(other) ⇒ Object



47
48
49
# File 'lib/tco/palette.rb', line 47

def -(other)
  delta_e_2000 @lab, other.lab
end

#<=>(other) ⇒ Object



51
52
53
# File 'lib/tco/palette.rb', line 51

def <=>(other)
  self.hsl[0] <=> other.hsl[0]
end

#hslObject



69
70
71
72
73
74
75
# File 'lib/tco/palette.rb', line 69

def hsl
  if @hsl == nil
    @hsl = rgb_to_hsl @rgb
  else
    @hsl
  end
end

#to_sObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tco/palette.rb', line 55

def to_s
  values = @rgb.map do |v|
    v = v.to_i.to_s 16

    case v.length
    when 0 then "00"
    when 1 then "0" + v
    when 2 then v
    end
  end

  "#" + values.join("")
end

#yiqObject



77
78
79
80
81
82
83
# File 'lib/tco/palette.rb', line 77

def yiq
  if @yiq == nil
    @yiq = rgb_to_yiq @rgb
  else
    @yiq
  end
end