Class: ZPNG::Color
- Inherits:
-
Struct
- Object
- Struct
- ZPNG::Color
- Defined in:
- lib/zpng/color.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#a ⇒ Object
(also: #alpha)
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
- #alpha=(v) ⇒ Object
- #black? ⇒ Boolean
-
#initialize(*args) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
- #to_grayscale ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #transparent? ⇒ Boolean
- #white? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Color
Returns a new instance of Color.
4 5 6 7 |
# File 'lib/zpng/color.rb', line 4 def initialize *args super self.a ||= 0xff end |
Instance Attribute Details
#a ⇒ Object Also known as: alpha
Returns the value of attribute a
2 3 4 |
# File 'lib/zpng/color.rb', line 2 def a @a end |
#b ⇒ Object
Returns the value of attribute b
2 3 4 |
# File 'lib/zpng/color.rb', line 2 def b @b end |
#g ⇒ Object
Returns the value of attribute g
2 3 4 |
# File 'lib/zpng/color.rb', line 2 def g @g end |
#r ⇒ Object
Returns the value of attribute r
2 3 4 |
# File 'lib/zpng/color.rb', line 2 def r @r end |
Class Method Details
Instance Method Details
#alpha=(v) ⇒ Object
10 |
# File 'lib/zpng/color.rb', line 10 def alpha= v; self.a = v; end |
#black? ⇒ Boolean
19 20 21 |
# File 'lib/zpng/color.rb', line 19 def black? r == 0 && g == 0 && b == 0 end |
#inspect ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zpng/color.rb', line 43 def inspect if r && g && b && a "#<ZPNG::Color #%02x%02x%02x a=%d>" % [r,g,b,a] else rs = r ? "%02x" % r : "??" gs = g ? "%02x" % g : "??" bs = b ? "%02x" % b : "??" as = a ? "%d" % a : "?" "#<ZPNG::Color #%s%s%s%s a=%s>" % [rs,gs,bs,as] end end |
#to_grayscale ⇒ Object
27 28 29 |
# File 'lib/zpng/color.rb', line 27 def to_grayscale (r+g+b)/3 end |
#to_i ⇒ Object
39 40 41 |
# File 'lib/zpng/color.rb', line 39 def to_i ((a||0) << 24) + ((r||0) << 16) + ((g||0) << 8) + (b||0) end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/zpng/color.rb', line 35 def to_s "%02X%02X%02X" % [r,g,b] end |
#transparent? ⇒ Boolean
23 24 25 |
# File 'lib/zpng/color.rb', line 23 def transparent? a == 0 end |
#white? ⇒ Boolean
15 16 17 |
# File 'lib/zpng/color.rb', line 15 def white? r == 0xff && g == 0xff && b == 0xff end |