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



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

Returns:

  • (Boolean)


82
83
84
# File 'lib/rays/color.rb', line 82

def eql?(o)
  self == o
end

#hashObject



78
79
80
# File 'lib/rays/color.rb', line 78

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

#inspectObject



86
87
88
# File 'lib/rays/color.rb', line 86

def inspect()
  "#<#{self.class.name} #{to_a.join ' '}>"
end

#opaque?Boolean

Returns:

  • (Boolean)


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

def opaque?()
  alpha >= 1
end

#to_aObject



43
44
45
# File 'lib/rays/color.rb', line 43

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

#to_sObject



47
48
49
# File 'lib/rays/color.rb', line 47

def to_s()
  to_a.to_s
end

#translucent?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/rays/color.rb', line 34

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

#transparent?Boolean

Returns:

  • (Boolean)


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

def transparent?()
  alpha <= 0
end