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.
369 370 371 |
# File 'lib/zyps.rb', line 369 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.
367 368 369 |
# File 'lib/zyps.rb', line 367 def blue @blue end |
#green ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
367 368 369 |
# File 'lib/zyps.rb', line 367 def green @green end |
#red ⇒ Object
Components which range from 0 to 1, which combine to form the Color.
367 368 369 |
# File 'lib/zyps.rb', line 367 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.
390 391 392 393 394 395 396 |
# File 'lib/zyps.rb', line 390 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.
385 386 387 |
# File 'lib/zyps.rb', line 385 def <=>(other) @red + @green + @blue <=> other.red + other.green + other.blue end |
#copy ⇒ Object
Make a deep copy.
374 |
# File 'lib/zyps.rb', line 374 def copy; self.clone; end |