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



72
73
74
75
76
77
# File 'lib/rays/color.rb', line 72

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



52
53
54
55
56
57
58
59
60
# File 'lib/rays/color.rb', line 52

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



62
63
64
65
66
67
68
69
70
# File 'lib/rays/color.rb', line 62

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



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

def each (&block)
  to_a.each &block
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql? (o)
  self == o
end

#hashObject



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

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

#inspectObject



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

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

#opaque?Boolean

Returns:

  • (Boolean)


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

def opaque? ()
  alpha >= 1
end

#to_aObject



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

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

#to_sObject



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

def to_s ()
  to_a.to_s
end

#translucent?Boolean

Returns:

  • (Boolean)


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

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

#transparent?Boolean

Returns:

  • (Boolean)


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

def transparent? ()
  alpha <= 0
end