Class: Tco::Colour
- Inherits:
-
Object
- Object
- Tco::Colour
- Defined in:
- lib/tco/palette.rb
Instance Attribute Summary collapse
-
#lab ⇒ Object
readonly
Returns the value of attribute lab.
-
#rgb ⇒ Object
readonly
Returns the value of attribute rgb.
Instance Method Summary collapse
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #hsl ⇒ Object
-
#initialize(rgb, lab = nil) ⇒ Colour
constructor
A new instance of Colour.
- #to_s ⇒ Object
- #yiq ⇒ Object
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
#lab ⇒ Object (readonly)
Returns the value of attribute lab.
38 39 40 |
# File 'lib/tco/palette.rb', line 38 def lab @lab end |
#rgb ⇒ Object (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 |
#hsl ⇒ Object
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_s ⇒ Object
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 |
#yiq ⇒ Object
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 |