Rings
Version 0.3

threeD.raytracer.graphics
Class RGB

java.lang.Object
  extended bythreeD.raytracer.graphics.RGB
All Implemented Interfaces:
java.lang.Cloneable, ColorProducer, Producer

public class RGB
extends java.lang.Object
implements java.lang.Cloneable, ColorProducer

An RGB object represents a color defined by three channels: red, green, and blue. An RGB object stores these channels as double values between 0.0 (no color) and 1.0 (strongest color).


Constructor Summary
RGB()
          Constructs an RGB object with all channels set to 0.0.
RGB(double r, double g, double b)
          Constructs an RGB object with the specified red (r), green (g), and blue (b) channel values.
 
Method Summary
 RGB add(RGB rgb)
          Returns the sum of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object.
 void addTo(RGB rgb)
          Adds the specified RGB object to this RGB object.
 java.lang.Object clone()
           
 RGB divide(double value)
          Returns the quotient of the division of the RGB value represented by this RGB object as an RGB object.
 RGB divide(RGB rgb)
          Returns the quotient of the division of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object.
 void divideBy(double value)
          Divides this RGB object by the specified value.
 void divideBy(RGB rgb)
          Divides this RGB object by the specified RGB object.
 boolean equals(RGB rgb)
          Returns true if the color represented by this RGB object is the same as the color represented by the specified RGB object, false otherwise.
 RGB evaluate(java.lang.Object[] args)
          Produces a color using the specified arguments.
 double getBlue()
          Returns the value of the blue channel of this RGB object as a double value.
 double getGreen()
          Returns the value of the green channel of this RGB object as a double value.
 double getRed()
          Returns the value of the red channel of this RGB object as a double value.
 int hashCode()
          Returns an integer hash code for this RGB object.
 RGB multiply(double value)
          Returns the product of the RGB value represented by this RGB object and the specified double value as an RGB object.
 RGB multiply(RGB rgb)
          Returns the product of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object.
 void multiplyBy(double value)
          Multiplies this RGB object by the specified double value.
 void multiplyBy(RGB rgb)
          Multiplies this RGB object by the specified RGB object.
 void setBlue(double b)
          Sets the value of the blue channel of this RGB object to the specified double value.
 void setGreen(double g)
          Sets the value of the green channel of this RGB to the specified double value.
 void setRed(double r)
          Sets the value of the red channel of this RGB object to the specified double value.
 RGB subtract(RGB rgb)
          Returns the difference of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object.
 void subtractFrom(RGB rgb)
          Subtracts the specified RGB object from this RGB object.
 java.lang.String toString()
          Returns a String representation of this RGB object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RGB

public RGB()
Constructs an RGB object with all channels set to 0.0.


RGB

public RGB(double r,
           double g,
           double b)
Constructs an RGB object with the specified red (r), green (g), and blue (b) channel values. If any of the values are less than 0.0, the channel will be set to 0.0. If any value is greater than 1.0, the channel is set 1.0.

Method Detail

setRed

public void setRed(double r)
Sets the value of the red channel of this RGB object to the specified double value. If the value is less than 0.0, the channel is set to 0.0. If the value is greater than 1.0, the channel is set to 1.0.


setGreen

public void setGreen(double g)
Sets the value of the green channel of this RGB to the specified double value. If the value is less than 0.0, the channel is set to 0.0. If the value is greater than 1.0, the channel is set to 1.0.


setBlue

public void setBlue(double b)
Sets the value of the blue channel of this RGB object to the specified double value. If the value is less than 0.0, the channel is set to 0.0. If the value is greater than 1.0, the channel is set to 1.0.


getRed

public double getRed()
Returns the value of the red channel of this RGB object as a double value.


getGreen

public double getGreen()
Returns the value of the green channel of this RGB object as a double value.


getBlue

public double getBlue()
Returns the value of the blue channel of this RGB object as a double value.


add

public RGB add(RGB rgb)
Returns the sum of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object. Consider using the addTo method to avoid creating unnecessary new RGB objects.


addTo

public void addTo(RGB rgb)
Adds the specified RGB object to this RGB object.

Parameters:
rgb - Value to add.

subtract

public RGB subtract(RGB rgb)
Returns the difference of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object. Consider using the subtractFrom method to avoid creating unnecessary new RGB objects.


subtractFrom

public void subtractFrom(RGB rgb)
Subtracts the specified RGB object from this RGB object.

Parameters:
rgb - Value to subtract.

multiply

public RGB multiply(double value)
Returns the product of the RGB value represented by this RGB object and the specified double value as an RGB object. Consider using the multiplyBy method to avoid creating unnecessary new RGB objects.


multiplyBy

public void multiplyBy(double value)
Multiplies this RGB object by the specified double value.

Parameters:
value - Value to multiply by.

multiply

public RGB multiply(RGB rgb)
Returns the product of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object. Consider using the multiplyBy method to avoid creating unnecessary new RGB objects.


multiplyBy

public void multiplyBy(RGB rgb)
Multiplies this RGB object by the specified RGB object.

Parameters:
rgb - Value to multiply by.

divide

public RGB divide(double value)
Returns the quotient of the division of the RGB value represented by this RGB object as an RGB object. Consider using the divideBy method to avoid creating unnecessary new RGB objects.


divideBy

public void divideBy(double value)
Divides this RGB object by the specified value.

Parameters:
value - Value to divide by.

divide

public RGB divide(RGB rgb)
Returns the quotient of the division of the RGB value represented by this RGB object and that of the specified RGB object as an RGB object. Consider using the divideBy method to avoid creating unnecessary new RGB objects.


divideBy

public void divideBy(RGB rgb)
Divides this RGB object by the specified RGB object.

Parameters:
rgb - Value to divide by.

evaluate

public RGB evaluate(java.lang.Object[] args)
Description copied from interface: ColorProducer
Produces a color using the specified arguments.

Specified by:
evaluate in interface ColorProducer
Parameters:
args - Arguments.
Returns:
this.

equals

public boolean equals(RGB rgb)
Returns true if the color represented by this RGB object is the same as the color represented by the specified RGB object, false otherwise.


hashCode

public int hashCode()
Returns an integer hash code for this RGB object.


clone

public java.lang.Object clone()
Returns:
An RGB object that represents the same color as this RGB object.

toString

public java.lang.String toString()
Returns a String representation of this RGB object.


Rings
Version 0.3

Copyright 2003-05 Mike Murray