Class: BaseColor

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

Overview

Copyright © 2007-2010 Logintas AG Switzerland

This file is part of Libisi.

Libisi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Libisi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Libisi. If not, see <www.gnu.org/licenses/>.

Direct Known Subclasses

ColortoolsColor, JavaColor

Instance Method Summary collapse

Instance Method Details

#adjust(property, value = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/libisi/color/base.rb', line 55

def adjust(property, value=nil)
  return self.send("#{property.to_s}_implementation") if value == nil

  case value
  when /^((\+|\-)?\d+\.?\d*)%/
    self.send("#{property.to_s}_percentage_implementation",$1.to_f)
  else
    raise "Not implemented hue #{value}"
  end    
end

#blueObject



31
# File 'lib/libisi/color/base.rb', line 31

def blue; rgb[2]; end

#blue=(val) ⇒ Object



32
# File 'lib/libisi/color/base.rb', line 32

def blue=(val); self.rgb=[red,green,val]; end

#brightness(value = nil) ⇒ Object



52
# File 'lib/libisi/color/base.rb', line 52

def brightness(value=nil); adjust(:brightness, value); end

#greenObject



29
# File 'lib/libisi/color/base.rb', line 29

def green; rgb[1]; end

#green=(val) ⇒ Object



30
# File 'lib/libisi/color/base.rb', line 30

def green=(val); self.rgb=[red,val,blue]; end

#hue(value = nil) ⇒ Object



51
# File 'lib/libisi/color/base.rb', line 51

def hue(value=nil); adjust(:hue, value); end

#object(type_name) ⇒ Object



20
21
22
23
24
25
# File 'lib/libisi/color/base.rb', line 20

def object(type_name)
  case type_name
  when "java", "java/paint"
    Color.create("java", self)
  end
end

#redObject



27
# File 'lib/libisi/color/base.rb', line 27

def red; rgb[0]; end

#red=(val) ⇒ Object



28
# File 'lib/libisi/color/base.rb', line 28

def red=(val); self.rgb=[val,green,blue]; end

#rgbObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/libisi/color/base.rb', line 33

def rgb
  h = html
  h = $1 if h =~ /^\#(.*)\;?$/    
  case h.length
  when 3
    [h[0..0].hex,h[1..1].hex,h[2..2].hex]
  when 6
    [h[0..1].hex,h[2..3].hex,h[4..5].hex]
  else
    raise "Unexpected html value #{html.inspect}"
  end
end

#rgb=(values) ⇒ Object



46
47
48
49
# File 'lib/libisi/color/base.rb', line 46

def rgb=(values)
  r,g,b = values
  self.html = r.to_s(16).rjust(2,"0") + g.to_s(16).rjust(2,"0") + b.to_s(16).rjust(2,"0")
end

#saturation(value = nil) ⇒ Object



53
# File 'lib/libisi/color/base.rb', line 53

def saturation(value=nil); adjust(:saturation, value); end