Class: Pikl::Color

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c, d) ⇒ Color

Returns a new instance of Color.



5
6
7
8
9
10
11
# File 'lib/pikl/color.rb', line 5

def initialize(a,b,c,d)
  validate_color(a)
  validate_color(b)
  validate_color(c)
  validate_color(d)
  @color = Pikl::Ext.pkl_color_create(a,b,c,d)
end

Class Method Details

.cmyk(c, m, y, k) ⇒ Object



21
22
23
# File 'lib/pikl/color.rb', line 21

def Color.cmyk(c,m,y,k)
  new(c,m,y,k)
end

.gray(g) ⇒ Object



13
14
15
# File 'lib/pikl/color.rb', line 13

def Color.gray(g)
  new(g,0,0,0)
end

.rgb(r, g, b) ⇒ Object



17
18
19
# File 'lib/pikl/color.rb', line 17

def Color.rgb(r, g, b)
  new(r,g,b,0)
end

Instance Method Details

#closeObject



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

def close
  Ext.pkl_color_close(@color)
  @color=nil
end

#getcolor(colormodel) ⇒ Object



30
31
32
33
# File 'lib/pikl/color.rb', line 30

def getcolor(colormodel)
  error("invalid colormodel parameter. # => #{colormodel}") unless COLORMODEL.include?(colormodel)
  Ext.pkl_color(@color, COLORMODEL[colormodel])
end

#rawdataObject

attr_accessor :color



26
27
28
# File 'lib/pikl/color.rb', line 26

def rawdata
  @color
end

#validate_color(v) ⇒ Object



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

def validate_color(v)
  error("invalid color parameter. # => #{v}") unless /^\d+$/ =~ v.to_s
  error("invalid color parameter. # => #{v}") unless v.to_i >= 0 && v.to_i <= 255
end