Class: Color

Inherits:
Object
  • Object
show all
Defined in:
lib/color.rb

Overview

The RGBA color class. Each component is handled with a floating point value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(red, green, blue, alpha = 255) ⇒ Color

Creates a Color object. If alpha is omitted, it is assumed at 255.


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

def initialize(red, green, blue, alpha=255)
  set red, green, blue, alpha
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha


3
4
5
# File 'lib/color.rb', line 3

def alpha
  @alpha
end

#blueObject

Returns the value of attribute blue


3
4
5
# File 'lib/color.rb', line 3

def blue
  @blue
end

#greenObject

Returns the value of attribute green


3
4
5
# File 'lib/color.rb', line 3

def green
  @green
end

#redObject

Returns the value of attribute red


3
4
5
# File 'lib/color.rb', line 3

def red
  @red
end

Instance Method Details

#set(red, green, blue, alpha = 255) ⇒ Object

Sets all components at once.


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

def set(red, green, blue, alpha=255)
  self.red   = red
  self.green = green
  self.blue  = blue
  self.alpha = alpha
end