org.jscience.computing.ai.util
Class Gradient

java.lang.Object
  extended by org.jscience.computing.ai.util.Gradient

public class Gradient
extends java.lang.Object

This class provides a method of creating a smooth gradient between up to 10 evenly distributed colour points. To create a gradient, add up to 10 colours and call createGradient. getColour or getGradient can be used to retrieve the resultant colours.


Constructor Summary
Gradient()
          Creates a new instance of Gradient.
 
Method Summary
 void addPoint(java.awt.Color gradientColour)
          Add a colour to the gradient list.
 void createGradient()
          Create the gradient using the current gradient list.
 void createGradient(int numSteps)
          Create the gradient using the current gradient list.
 java.awt.Color getColour(int i)
          Return the ith colour in the gradient.
 java.awt.Color[] getGradient()
          Return the entire gradient as a Color array.
protected  double[] getRGBDeltas(java.awt.Color start, java.awt.Color end, int steps)
          Calculate the RGB deltas between two different colour values and over a given number of timesteps.
static void main(java.lang.String[] args)
          Test function.
 void reset()
          Reset the gradient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gradient

public Gradient()
Creates a new instance of Gradient.

Method Detail

addPoint

public void addPoint(java.awt.Color gradientColour)
Add a colour to the gradient list. A maximum of 10 colour points are allowed, any more will throw an exception.

Parameters:
gradientColour - the next colour in the gradient.

reset

public void reset()
Reset the gradient.


getRGBDeltas

protected double[] getRGBDeltas(java.awt.Color start,
                                java.awt.Color end,
                                int steps)
Calculate the RGB deltas between two different colour values and over a given number of timesteps. createGradient uses this function to connect the gradient points together.

Parameters:
start - the starting colour.
end - the ending colour.
steps - the number of steps required to get from start to endReturns:
a double[3] array returning the red, green and blue delta values.

createGradient

public void createGradient()
Create the gradient using the current gradient list. This method defaults to using 256 steps.


createGradient

public void createGradient(int numSteps)
Create the gradient using the current gradient list.

Parameters:
numSteps - the number of steps to take from the first colour to the last.

getColour

public java.awt.Color getColour(int i)
Return the ith colour in the gradient.

Parameters:
i - the index of gradient array to return.
Returns:
the Color value in the gradient.

getGradient

public java.awt.Color[] getGradient()
Return the entire gradient as a Color array.

Returns:
Color[256] containing the gradient colours.

main

public static void main(java.lang.String[] args)
Test function.

Parameters:
args - command-line arguments (ignored).