Class: Rays::Color
- Inherits:
-
Object
- Object
- Rays::Color
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/rays/color.rb
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #[](index) ⇒ Object
- #[]=(index, val) ⇒ Object
- #each(&block) ⇒ Object
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
- #inspect ⇒ Object
- #opaque? ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
- #translucent? ⇒ Boolean
- #transparent? ⇒ Boolean
Instance Method Details
#<=>(o) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/rays/color.rb', line 71 def <=>(o) ret = red <=> o.red; return ret if ret != 0 ret = green <=> o.green; return ret if ret != 0 ret = blue <=> o.blue; return ret if ret != 0 alpha <=> o.alpha end |
#[](index) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/rays/color.rb', line 51 def [](index) case index when 0 then red when 1 then green when 2 then blue when 3 then alpha else raise IndexError end end |
#[]=(index, val) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rays/color.rb', line 61 def []=(index, val) case index when 0 then self.red = val when 1 then self.green = val when 2 then self.blue = val when 3 then self.alpha = val else raise IndexError end end |
#each(&block) ⇒ Object
39 40 41 |
# File 'lib/rays/color.rb', line 39 def each(&block) to_a.each(&block) end |
#eql?(o) ⇒ Boolean
82 83 84 |
# File 'lib/rays/color.rb', line 82 def eql?(o) self == o end |
#hash ⇒ Object
78 79 80 |
# File 'lib/rays/color.rb', line 78 def hash() red.hash + green.hash + blue.hash + alpha.hash end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/rays/color.rb', line 86 def inspect() "#<#{self.class.name} #{to_a.join ' '}>" end |
#opaque? ⇒ Boolean
26 27 28 |
# File 'lib/rays/color.rb', line 26 def opaque?() alpha >= 1 end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/rays/color.rb', line 43 def to_a() [red, green, blue, alpha] end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/rays/color.rb', line 47 def to_s() to_a.to_s end |
#translucent? ⇒ Boolean
34 35 36 37 |
# File 'lib/rays/color.rb', line 34 def translucent?() a = alpha 0 < a && a < 1 end |
#transparent? ⇒ Boolean
30 31 32 |
# File 'lib/rays/color.rb', line 30 def transparent?() alpha <= 0 end |