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
69 70 71 72 73 74 |
# File 'lib/rays/color.rb', line 69 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
49 50 51 52 53 54 55 56 57 |
# File 'lib/rays/color.rb', line 49 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
59 60 61 62 63 64 65 66 67 |
# File 'lib/rays/color.rb', line 59 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
37 38 39 |
# File 'lib/rays/color.rb', line 37 def each(&block) to_a.each(&block) end |
#eql?(o) ⇒ Boolean
80 81 82 |
# File 'lib/rays/color.rb', line 80 def eql?(o) self == o end |
#hash ⇒ Object
76 77 78 |
# File 'lib/rays/color.rb', line 76 def hash() red.hash + green.hash + blue.hash + alpha.hash end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/rays/color.rb', line 84 def inspect() "#<#{self.class.name} #{to_s}>" end |
#opaque? ⇒ Boolean
24 25 26 |
# File 'lib/rays/color.rb', line 24 def opaque?() alpha >= 1 end |
#to_a ⇒ Object
41 42 43 |
# File 'lib/rays/color.rb', line 41 def to_a() [red, green, blue, alpha] end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/rays/color.rb', line 45 def to_s() to_a.to_s end |
#translucent? ⇒ Boolean
32 33 34 35 |
# File 'lib/rays/color.rb', line 32 def translucent?() a = alpha 0 < a && a < 1 end |
#transparent? ⇒ Boolean
28 29 30 |
# File 'lib/rays/color.rb', line 28 def transparent?() alpha <= 0 end |