Class: Rays::Color

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/rays/color.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


80
81
82
# File 'lib/rays/color.rb', line 80

def eql?(o)
  self == o
end

#hashObject



76
77
78
# File 'lib/rays/color.rb', line 76

def hash()
  red.hash + green.hash + blue.hash + alpha.hash
end

#inspectObject



84
85
86
# File 'lib/rays/color.rb', line 84

def inspect()
  "#<#{self.class.name} #{to_s}>"
end

#opaque?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rays/color.rb', line 24

def opaque?()
  alpha >= 1
end

#to_aObject



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

def to_a()
  [red, green, blue, alpha]
end

#to_sObject



45
46
47
# File 'lib/rays/color.rb', line 45

def to_s()
  to_a.to_s
end

#translucent?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/rays/color.rb', line 32

def translucent?()
  a = alpha
  0 < a && a < 1
end

#transparent?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rays/color.rb', line 28

def transparent?()
  alpha <= 0
end