com.jme3.math
Class ColorRGBA

java.lang.Object
  extended by com.jme3.math.ColorRGBA
All Implemented Interfaces:
Savable, java.io.Serializable, java.lang.Cloneable

public final class ColorRGBA
extends java.lang.Object
implements Savable, java.lang.Cloneable, java.io.Serializable

ColorRGBA defines a color made from a collection of red, green and blue values. An alpha value determines is transparency. All values must be between 0 and 1. If any value is set higher or lower than these constraints they are clamped to the min or max. That is, if a value smaller than zero is set the value clamps to zero. If a value higher than 1 is passed, that value is clamped to 1. However, because the attributes r, g, b, a are public for efficiency reasons, they can be directly modified with invalid values. The client should take care when directly addressing the values. A call to clamp will assure that the values are within the constraints.

See Also:
Serialized Form

Field Summary
 float a
          the alpha component of the color.
 float b
          the blue component of the color.
static ColorRGBA Black
          the color black (0,0,0).
static ColorRGBA BlackNoAlpha
          the black color with no alpha (0, 0, 0, 0);
static ColorRGBA Blue
          the color blue (0,0,1).
static ColorRGBA Brown
          the color brown (65/255, 40/255, 25/255).
static ColorRGBA Cyan
          the color cyan (0,1,1).
static ColorRGBA DarkGray
          the color gray (.2,.2,.2).
 float g
          The green component of the color.
static ColorRGBA Gray
          the color gray (.5,.5,.5).
static ColorRGBA Green
          the color green (0,1,0).
static ColorRGBA LightGray
          the color gray (.8,.8,.8).
static ColorRGBA Magenta
          the color magenta (1,0,1).
static ColorRGBA Orange
          the color orange (251/255, 130/255,0).
static ColorRGBA Pink
          the color pink (1, 0.68, 0.68).
 float r
          The red component of the color.
static ColorRGBA Red
          the color red (1,0,0).
static ColorRGBA White
          the color white (1,1,1).
static ColorRGBA Yellow
          the color yellow (1,1,0).
 
Constructor Summary
ColorRGBA()
          Constructor instantiates a new ColorRGBA object.
ColorRGBA(ColorRGBA rgba)
          Copy constructor creates a new ColorRGBA object, based on a provided color.
ColorRGBA(float r, float g, float b, float a)
          Constructor instantiates a new ColorRGBA object.
 
Method Summary
 ColorRGBA add(ColorRGBA c)
          Adds each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA.
 ColorRGBA addLocal(ColorRGBA c)
          Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA.
 byte[] asBytesRGBA()
           
 int asIntABGR()
           
 int asIntARGB()
           
 int asIntRGBA()
           
 void clamp()
          clamp insures that all values are between 0 and 1.
 ColorRGBA clone()
           
 boolean equals(java.lang.Object o)
          equals returns true if this color is logically equivalent to a given color.
 void fromIntARGB(int color)
           
 void fromIntRGBA(int color)
           
 float getAlpha()
           
 float getBlue()
           
 float[] getColorArray()
          getColorArray retrieves the color values of this object as a four element float array.
 float[] getColorArray(float[] store)
          Stores the current r/g/b/a values into the tempf array.
 float getGreen()
           
 float getRed()
           
 int hashCode()
          hashCode returns a unique code for this color object based on it's values.
 void interpolate(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmnt)
          Sets this color to the interpolation by changeAmnt from beginColor to finalColor this=(1-changeAmnt)*beginColor + changeAmnt * finalColor
 void interpolate(ColorRGBA finalColor, float changeAmnt)
          Sets this color to the interpolation by changeAmnt from this to the finalColor this=(1-changeAmnt)*this + changeAmnt * finalColor
 ColorRGBA mult(ColorRGBA c)
          Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA.
 ColorRGBA mult(float scalar)
          Multiplies each r/g/b/a of this color by the given scalar and returns the result as a new ColorRGBA.
 ColorRGBA multLocal(float scalar)
          Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA.
static ColorRGBA randomColor()
          randomColor is a utility method that generates a random color.
 void read(JmeImporter e)
           
 ColorRGBA set(ColorRGBA rgba)
          set sets the values of this color to those set by a parameter color.
 ColorRGBA set(float r, float g, float b, float a)
          set sets the RGBA values of this color.
 float[] toArray(float[] floats)
          Saves this ColorRGBA into the given float[] object.
 java.lang.String toString()
          toString returns the string representation of this color.
 Vector3f toVector3f()
          Transform the current ColorRGBA to a Vector3f using x = r, y = g, z = b.
 Vector4f toVector4f()
          Transform the current ColorRGBA to a Vector4f using x = r, y = g, z = b, w = a.
 void write(JmeExporter e)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

Black

public static final ColorRGBA Black
the color black (0,0,0).


White

public static final ColorRGBA White
the color white (1,1,1).


DarkGray

public static final ColorRGBA DarkGray
the color gray (.2,.2,.2).


Gray

public static final ColorRGBA Gray
the color gray (.5,.5,.5).


LightGray

public static final ColorRGBA LightGray
the color gray (.8,.8,.8).


Red

public static final ColorRGBA Red
the color red (1,0,0).


Green

public static final ColorRGBA Green
the color green (0,1,0).


Blue

public static final ColorRGBA Blue
the color blue (0,0,1).


Yellow

public static final ColorRGBA Yellow
the color yellow (1,1,0).


Magenta

public static final ColorRGBA Magenta
the color magenta (1,0,1).


Cyan

public static final ColorRGBA Cyan
the color cyan (0,1,1).


Orange

public static final ColorRGBA Orange
the color orange (251/255, 130/255,0).


Brown

public static final ColorRGBA Brown
the color brown (65/255, 40/255, 25/255).


Pink

public static final ColorRGBA Pink
the color pink (1, 0.68, 0.68).


BlackNoAlpha

public static final ColorRGBA BlackNoAlpha
the black color with no alpha (0, 0, 0, 0);


r

public float r
The red component of the color.


g

public float g
The green component of the color.


b

public float b
the blue component of the color.


a

public float a
the alpha component of the color. 0 is transparent and 1 is opaque

Constructor Detail

ColorRGBA

public ColorRGBA()
Constructor instantiates a new ColorRGBA object. This color is the default "white" with all values 1.


ColorRGBA

public ColorRGBA(float r,
                 float g,
                 float b,
                 float a)
Constructor instantiates a new ColorRGBA object. The values are defined as passed parameters. These values are then clamped to insure that they are between 0 and 1.

Parameters:
r - the red component of this color.
g - the green component of this color.
b - the blue component of this color.
a - the alpha component of this color.

ColorRGBA

public ColorRGBA(ColorRGBA rgba)
Copy constructor creates a new ColorRGBA object, based on a provided color.

Parameters:
rgba - the ColorRGBA object to copy.
Method Detail

set

public ColorRGBA set(float r,
                     float g,
                     float b,
                     float a)
set sets the RGBA values of this color. The values are then clamped to insure that they are between 0 and 1.

Parameters:
r - the red component of this color.
g - the green component of this color.
b - the blue component of this color.
a - the alpha component of this color.
Returns:
this

set

public ColorRGBA set(ColorRGBA rgba)
set sets the values of this color to those set by a parameter color.

Parameters:
rgba - ColorRGBA the color to set this color to.
Returns:
this

clamp

public void clamp()
clamp insures that all values are between 0 and 1. If any are less than 0 they are set to zero. If any are more than 1 they are set to one.


getColorArray

public float[] getColorArray()
getColorArray retrieves the color values of this object as a four element float array.

Returns:
the float array that contains the color elements.

getColorArray

public float[] getColorArray(float[] store)
Stores the current r/g/b/a values into the tempf array. The tempf array must have a length of 4 or greater, or an array index out of bounds exception will be thrown.

Parameters:
store - The array of floats to store the values into.
Returns:
The float[] after storage.

getAlpha

public float getAlpha()

getRed

public float getRed()

getBlue

public float getBlue()

getGreen

public float getGreen()

interpolate

public void interpolate(ColorRGBA finalColor,
                        float changeAmnt)
Sets this color to the interpolation by changeAmnt from this to the finalColor this=(1-changeAmnt)*this + changeAmnt * finalColor

Parameters:
finalColor - The final color to interpolate towards
changeAmnt - An amount between 0.0 - 1.0 representing a precentage change from this towards finalColor

interpolate

public void interpolate(ColorRGBA beginColor,
                        ColorRGBA finalColor,
                        float changeAmnt)
Sets this color to the interpolation by changeAmnt from beginColor to finalColor this=(1-changeAmnt)*beginColor + changeAmnt * finalColor

Parameters:
beginColor - The begining color (changeAmnt=0)
finalColor - The final color to interpolate towards (changeAmnt=1)
changeAmnt - An amount between 0.0 - 1.0 representing a precentage change from beginColor towards finalColor

randomColor

public static ColorRGBA randomColor()
randomColor is a utility method that generates a random color.

Returns:
a random color.

mult

public ColorRGBA mult(ColorRGBA c)
Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA. Used as a way of combining colors and lights.

Parameters:
c - The color to multiply.
Returns:
The new ColorRGBA. this*c

mult

public ColorRGBA mult(float scalar)
Multiplies each r/g/b/a of this color by the given scalar and returns the result as a new ColorRGBA. Used as a way of making colors dimmer or brighter..

Parameters:
scalar - The scalar to multiply.
Returns:
The new ColorRGBA. this*scalar

multLocal

public ColorRGBA multLocal(float scalar)
Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA. Used as a way of combining colors and lights.

Parameters:
scalar - scalar to multiply with
Returns:
The new ColorRGBA. this*c

add

public ColorRGBA add(ColorRGBA c)
Adds each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA.

Parameters:
c - The color to add.
Returns:
The new ColorRGBA. this+c

addLocal

public ColorRGBA addLocal(ColorRGBA c)
Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and returns the result as a new ColorRGBA. Used as a way of combining colors and lights.

Parameters:
c - The color to multiply.
Returns:
The new ColorRGBA. this*c

toString

public java.lang.String toString()
toString returns the string representation of this color. The format of the string is:
: [R=RR.RRRR, G=GG.GGGG, B=BB.BBBB, A=AA.AAAA]

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this color.

clone

public ColorRGBA clone()
Overrides:
clone in class java.lang.Object

toArray

public float[] toArray(float[] floats)
Saves this ColorRGBA into the given float[] object.

Parameters:
floats - The float[] to take this ColorRGBA. If null, a new float[4] is created.
Returns:
The array, with R, G, B, A float values in that order

equals

public boolean equals(java.lang.Object o)
equals returns true if this color is logically equivalent to a given color. That is, if the values of the two colors are the same. False is returned otherwise.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare againts.
Returns:
true if the colors are equal, false otherwise.

hashCode

public int hashCode()
hashCode returns a unique code for this color object based on it's values. If two colors are logically equivalent, they will return the same hash code value.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value of this color.

write

public void write(JmeExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JmeImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

asBytesRGBA

public byte[] asBytesRGBA()

asIntARGB

public int asIntARGB()

asIntRGBA

public int asIntRGBA()

asIntABGR

public int asIntABGR()

fromIntARGB

public void fromIntARGB(int color)

fromIntRGBA

public void fromIntRGBA(int color)

toVector3f

public Vector3f toVector3f()
Transform the current ColorRGBA to a Vector3f using x = r, y = g, z = b. The Alpha value is not used. This method is useful to use for shaders assignment.

Returns:
A Vector3f containing the RGB value of current color definition.

toVector4f

public Vector4f toVector4f()
Transform the current ColorRGBA to a Vector4f using x = r, y = g, z = b, w = a. This method is useful to use for shaders assignment.

Returns:
A Vector4f containing the RGBA value of current color definition.