Class: Zyps::Color
Overview
An object’s color. Has red, green, and blue components, each ranging from 0 to 1.
-
Red:
Color.new(1, 0, 0)
-
Green:
Color.new(0, 1, 0)
-
Blue:
Color.new(0, 0, 1)
-
White:
Color.new(1, 1, 1)
-
Black:
Color.new(0, 0, 0)
Instance Attribute Summary collapse
-
#blue ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
-
#green ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
-
#red ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
Instance Method Summary collapse
-
#+(color2) ⇒ Object
Averages each component of this Color with the corresponding component of color2, returning a new Color.
-
#<=>(other) ⇒ Object
Compares this Color with another to see which is brighter.
-
#copy ⇒ Object
Make a deep copy.
-
#initialize(red = 1, green = 1, blue = 1) ⇒ Color
constructor
A new instance of Color.
Constructor Details
#initialize(red = 1, green = 1, blue = 1) ⇒ Color
Returns a new instance of Color.
407 408 409 |
# File 'lib/zyps.rb', line 407 def initialize (red = 1, green = 1, blue = 1) self.red, self.green, self.blue = red, green, blue end |
Instance Attribute Details
#blue ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
405 406 407 |
# File 'lib/zyps.rb', line 405 def blue @blue end |
#green ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
405 406 407 |
# File 'lib/zyps.rb', line 405 def green @green end |
#red ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
405 406 407 |
# File 'lib/zyps.rb', line 405 def red @red end |
Instance Method Details
#+(color2) ⇒ Object
Averages each component of this Color with the corresponding component of color2, returning a new Color.
428 429 430 431 432 433 434 |
# File 'lib/zyps.rb', line 428 def +(color2) Color.new( (self.red + color2.red) / 2.0, (self.green + color2.green) / 2.0, (self.blue + color2.blue) / 2.0 ) end |
#<=>(other) ⇒ Object
Compares this Color with another to see which is brighter. The sum of all components (red + green + blue) for each color determines which is greater.
423 424 425 |
# File 'lib/zyps.rb', line 423 def <=>(other) @red + @green + @blue <=> other.red + other.green + other.blue end |
#copy ⇒ Object
Make a deep copy.
412 |
# File 'lib/zyps.rb', line 412 def copy; self.clone; end |