Package com.ardor3d.math
Class ColorRGBA
java.lang.Object
com.ardor3d.math.ColorRGBA
- All Implemented Interfaces:
Poolable,ReadOnlyColorRGBA,Savable,Externalizable,Serializable,Cloneable
public class ColorRGBA
extends Object
implements Cloneable, Savable, Externalizable, ReadOnlyColorRGBA, Poolable
ColorRGBA is a 4 component color value (red, green, blue, alpha). The standard range for each individual component is
[0f, 1f]. Non-standard use of color (for example HDR rendering) may need to use values outside of this range however,
so the value is not clipped or enforced.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected floatprotected floatprotected floatstatic final ReadOnlyColorRGBAthe color black (0, 0, 0, 1).static final ReadOnlyColorRGBAthe color black with a zero alpha value (0, 0, 0, 0).static final ReadOnlyColorRGBAthe color blue (0, 0, 1, 1).static final ReadOnlyColorRGBAthe color brown (65/255f, 40/255f, 25/255f, 1).static final ReadOnlyColorRGBAthe color cyan (0, 1, 1, 1).static final ReadOnlyColorRGBAthe color gray (.2f, .2f, .2f, 1).static final ReadOnlyColorRGBAthe color gray (.5f, .5f, .5f, 1).static final ReadOnlyColorRGBAthe color green (0, 1, 0, 1).static final ReadOnlyColorRGBAthe color gray (.8f, .8f, .8f, 1).static final ReadOnlyColorRGBAthe color magenta (1, 0, 1, 1).static final ReadOnlyColorRGBAthe color orange (251/255f, 130/255f, 0, 1).static final ReadOnlyColorRGBAthe color pink (1, 0.68f, 0.68f, 1).static final ReadOnlyColorRGBAthe color red (1, 0, 0, 1).static final ReadOnlyColorRGBAthe color white (1, 1, 1, 1).static final ReadOnlyColorRGBAthe color yellow (1, 1, 0, 1). -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, mutable color set to (1, 1, 1, 1).ColorRGBA(float r, float g, float b, float a) Constructs a new color set to (r, g, b, a).Constructs a new, mutable color set to the (r, g, b, a) values of the provided source color. -
Method Summary
Modifier and TypeMethodDescriptionAdds the given values to those of this color and returns them in store.add(ReadOnlyColorRGBA source, ColorRGBA store) Adds the values of the given source color to those of this color and returns them in store.addLocal(float r, float g, float b, float a) Increments the values of this color with the given r, g, b and a values.addLocal(ReadOnlyColorRGBA source) Increments the values of this color with the r, g, b and a values of the given color.intintBrings all values (r,g,b,a) into the range [0.0f, 1.0f].Brings all values (r,g,b,a) into the range [0.0f, 1.0f].clone()Divides the values of this color by the given scalar value and returns the result in store.divide(ReadOnlyColorRGBA scale, ColorRGBA store) Divides the values of this color by the given scale values and returns the result in store.divideLocal(float scalar) Internally modifies the values of this color by dividing them each by the given scalar value.divideLocal(ReadOnlyColorRGBA scale) Internally modifies the values of this color by dividing them each by the given scale values.booleanstatic final ColorRGBAfromIntARGB(int color) Reads a color, packed into a 4 byte int as 1 byte values in the order ARGB.fromIntRGBA(int color) Reads a color, packed into a 4 byte int as 1 byte values in the order RGBA.floatgetAlpha()floatgetBlue()floatgetGreen()floatgetRed()floatgetValue(int index) inthashCode()static booleanisValid(ReadOnlyColorRGBA color) Check a color... if it is null or its values are NaN or infinite, return false.lerp(ReadOnlyColorRGBA endColor, float scalar, ColorRGBA store) Performs a linear interpolation between this color and the given end color, using the given scalar as a percent.static ColorRGBAlerp(ReadOnlyColorRGBA beginColor, ReadOnlyColorRGBA endColor, float scalar, ColorRGBA store) Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result will be closer to the end value.lerpLocal(ReadOnlyColorRGBA endColor, float scalar) Performs a linear interpolation between this color and the given end color, using the given scalar as a percent.lerpLocal(ReadOnlyColorRGBA beginColor, ReadOnlyColorRGBA endColor, float scalar) Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, if scalar is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result will be closer to the end value.Multiplies the values of this color by the given scalar value and returns the result in store.multiply(ReadOnlyColorRGBA scale, ColorRGBA store) Multiplies the values of this color by the given scalar value and returns the result in store.multiplyLocal(float scalar) Internally modifies the values of this color by multiplying them each by the given scalar value.multiplyLocal(ReadOnlyColorRGBA scale) Internally modifies the values of this color by multiplying them each by the given scale values.static ColorRGBAparseColor(String colorString, ColorRGBA store) Parses the given string for a color value.static ColorRGBArandomColor(ColorRGBA store) voidread(InputCapsule capsule) voidUsed with serialization.static final voidreleaseTempInstance(ColorRGBA color) Releases a ColorRGBA back to be used by a future call to fetchTempInstance.set(float r, float g, float b, float a) Sets the value of this color to (r, g, b, a)set(ReadOnlyColorRGBA source) Sets the value of this color to the (r, g, b, a) values of the provided source color.voidsetAlpha(float a) Sets the alpha component of this color to the given float value.voidsetBlue(float b) Sets the blue component of this color to the given float value.voidsetGreen(float g) Sets the green component of this color to the given float value.voidsetRed(float r) Sets the red component of this color to the given float value.voidsetValue(int index, float value) Subtracts the given values from those of this color and returns them in store.subtract(ReadOnlyColorRGBA source, ColorRGBA store) Subtracts the values of the given source color from those of this color and returns them in store.subtractLocal(float r, float g, float b, float a) Decrements the values of this color by the given r, g, b and a values.subtractLocal(ReadOnlyColorRGBA source) Decrements the values of this color by the r, g, b and a values from the given source color.float[]toArray(float[] store) Stores the float values of this color in the given float array.toString()voidwrite(OutputCapsule capsule) voidUsed with serialization.zero()Sets the value of this color to (0, 0, 0, 0)
-
Field Details
-
BLACK
the color black (0, 0, 0, 1). -
BLACK_NO_ALPHA
the color black with a zero alpha value (0, 0, 0, 0). -
WHITE
the color white (1, 1, 1, 1). -
DARK_GRAY
the color gray (.2f, .2f, .2f, 1). -
GRAY
the color gray (.5f, .5f, .5f, 1). -
LIGHT_GRAY
the color gray (.8f, .8f, .8f, 1). -
RED
the color red (1, 0, 0, 1). -
GREEN
the color green (0, 1, 0, 1). -
BLUE
the color blue (0, 0, 1, 1). -
YELLOW
the color yellow (1, 1, 0, 1). -
MAGENTA
the color magenta (1, 0, 1, 1). -
CYAN
the color cyan (0, 1, 1, 1). -
ORANGE
the color orange (251/255f, 130/255f, 0, 1). -
BROWN
the color brown (65/255f, 40/255f, 25/255f, 1). -
PINK
the color pink (1, 0.68f, 0.68f, 1). -
_r
protected float _r -
_g
protected float _g -
_b
protected float _b -
_a
protected float _a
-
-
Constructor Details
-
ColorRGBA
public ColorRGBA()Constructs a new, mutable color set to (1, 1, 1, 1). -
ColorRGBA
Constructs a new, mutable color set to the (r, g, b, a) values of the provided source color.- Parameters:
src- the source color
-
ColorRGBA
public ColorRGBA(float r, float g, float b, float a) Constructs a new color set to (r, g, b, a).- Parameters:
r- the red componentg- the green componentb- the blue componenta- the alpha component
-
-
Method Details
-
getRed
public float getRed()- Specified by:
getRedin interfaceReadOnlyColorRGBA
-
getGreen
public float getGreen()- Specified by:
getGreenin interfaceReadOnlyColorRGBA
-
getBlue
public float getBlue()- Specified by:
getBluein interfaceReadOnlyColorRGBA
-
getAlpha
public float getAlpha()- Specified by:
getAlphain interfaceReadOnlyColorRGBA
-
getValue
public float getValue(int index) - Specified by:
getValuein interfaceReadOnlyColorRGBA- Parameters:
index- the field index in this color, must be either 0, 1, 2 or 3- Returns:
- r value if index == 0, g value if index == 1, b value if index == 2 or a value if index == 3
- Throws:
IllegalArgumentException- if index is not one of 0, 1, 2, 3.
-
setValue
public void setValue(int index, float value) - Parameters:
index- which field index in this color to set.value- to set to one of r, g, b or a.- Throws:
IllegalArgumentException- if index is not one of 0, 1, 2, 3.
-
toArray
public float[] toArray(float[] store) Stores the float values of this color in the given float array.- Specified by:
toArrayin interfaceReadOnlyColorRGBA- Parameters:
store- if null, a new float[4] array is created.- Returns:
- the float array
- Throws:
NullPointerException- if store is null.ArrayIndexOutOfBoundsException- if store is not at least length 4.
-
setRed
public void setRed(float r) Sets the red component of this color to the given float value.- Parameters:
r- new red value, generally should be in the range [0.0f, 1.0f]
-
setGreen
public void setGreen(float g) Sets the green component of this color to the given float value.- Parameters:
g- new green value, generally should be in the range [0.0f, 1.0f]
-
setBlue
public void setBlue(float b) Sets the blue component of this color to the given float value.- Parameters:
b- new blue value, generally should be in the range [0.0f, 1.0f]
-
setAlpha
public void setAlpha(float a) Sets the alpha component of this color to the given float value. Consider that an alpha of 1.0f means opaque (can not see through) and 0.0f means transparent.- Parameters:
a- new alpha value, generally should be in the range [0.0f, 1.0f]
-
set
Sets the value of this color to (r, g, b, a)- Parameters:
r- new red value, generally should be in the range [0.0f, 1.0f]g- new green value, generally should be in the range [0.0f, 1.0f]b- new blue value, generally should be in the range [0.0f, 1.0f]a- new alpha value, generally should be in the range [0.0f, 1.0f]- Returns:
- this color for chaining
-
set
Sets the value of this color to the (r, g, b, a) values of the provided source color.- Parameters:
source- the source color- Returns:
- this color for chaining
- Throws:
NullPointerException- if source is null.
-
zero
Sets the value of this color to (0, 0, 0, 0)- Returns:
- this color for chaining
-
clamp
Brings all values (r,g,b,a) into the range [0.0f, 1.0f]. If a value is above or below this range it is replaced with the appropriate end of the range.- Specified by:
clampin interfaceReadOnlyColorRGBA- Parameters:
store- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- the clamped color
-
clampLocal
Brings all values (r,g,b,a) into the range [0.0f, 1.0f]. If a value is above or below this range it is replaced with the appropriate end of the range.- Returns:
- this color for chaining
-
randomColor
- Parameters:
store- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a random, mutable opaque color.
-
asIntARGB
public int asIntARGB()- Specified by:
asIntARGBin interfaceReadOnlyColorRGBA- Returns:
- this color, stored as an integer by converting the values to the range [0, 255] and combining them as single byte values into a 4 byte int in the order ARGB. Note that this method expects color values in the [0.0f, 1.0f] range.
-
asIntRGBA
public int asIntRGBA()- Specified by:
asIntRGBAin interfaceReadOnlyColorRGBA- Returns:
- this color, stored as an integer by converting the values to the range [0, 255] and combining them as single byte values into a 4 byte int in the order RGBA. Note that this method expects color values in the [0.0f, 1.0f] range.
-
fromIntARGB
Reads a color, packed into a 4 byte int as 1 byte values in the order ARGB. These byte values are normalized to the range [0.0f, 1.0f]- Parameters:
color- the 4 byte int as 1 byte values in the order ARGB- Returns:
- this color for chaining
-
fromIntRGBA
Reads a color, packed into a 4 byte int as 1 byte values in the order RGBA. These byte values are normalized to the range [0.0f, 1.0f]- Parameters:
color- the 4 byte int as 1 byte values in the order RGBA- Returns:
- this color for chaining
-
asHexRRGGBBAA
- Specified by:
asHexRRGGBBAAin interfaceReadOnlyColorRGBA- Returns:
- this string as a hex value (#RRGGBBAA). e.g. opaque blue is #0000ffff
-
add
Adds the given values to those of this color and returns them in store.- Specified by:
addin interfaceReadOnlyColorRGBA- Parameters:
r- the red componentg- the green componentb- the blue componenta- the alpha componentstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- (this.r + r, this.g + g, this.b + b, this.a + a)
-
addLocal
Increments the values of this color with the given r, g, b and a values.- Parameters:
r- the red componentg- the green componentb- the blue componenta- the alpha component- Returns:
- this color for chaining
-
add
Adds the values of the given source color to those of this color and returns them in store.- Specified by:
addin interfaceReadOnlyColorRGBA- Parameters:
source- the source colorstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- (this.r + source.r, this.g + source.g, this.b + source.b, this.a + source.a)
- Throws:
NullPointerException- if source is null.
-
addLocal
Increments the values of this color with the r, g, b and a values of the given color.- Parameters:
source- the source color- Returns:
- this color for chaining
- Throws:
NullPointerException- if source is null.
-
subtract
Subtracts the given values from those of this color and returns them in store.- Specified by:
subtractin interfaceReadOnlyColorRGBA- Parameters:
r- the red componentg- the green componentb- the blue componenta- the alpha componentstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- (this.r - r, this.g - g, this.b - b, this.a - a)
-
subtractLocal
Decrements the values of this color by the given r, g, b and a values.- Parameters:
r- the red componentg- the green componentb- the blue componenta- the alpha component- Returns:
- this color for chaining
-
subtract
Subtracts the values of the given source color from those of this color and returns them in store.- Specified by:
subtractin interfaceReadOnlyColorRGBA- Parameters:
source- the source colorstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- (this.r - source.r, this.g - source.g, this.b - source.b, this.a - source.a)
- Throws:
NullPointerException- if source is null.
-
subtractLocal
Decrements the values of this color by the r, g, b and a values from the given source color.- Parameters:
source- the source color- Returns:
- this color for chaining
- Throws:
NullPointerException- if source is null.
-
multiply
Multiplies the values of this color by the given scalar value and returns the result in store.- Specified by:
multiplyin interfaceReadOnlyColorRGBA- Parameters:
scalar- the scalar valuestore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new color (this.r * scalar, this.g * scalar, this.b * scalar, this.a * scalar)
-
multiplyLocal
Internally modifies the values of this color by multiplying them each by the given scalar value.- Parameters:
scalar- the scalar value- Returns:
- this color for chaining
-
multiply
Multiplies the values of this color by the given scalar value and returns the result in store.- Specified by:
multiplyin interfaceReadOnlyColorRGBA- Parameters:
scale- the scale valuesstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new color (this.r * scale.r, this.g * scale.g, this.b * scale.b, this.a * scale.a)
-
multiplyLocal
Internally modifies the values of this color by multiplying them each by the given scale values.- Parameters:
scale- the scale values- Returns:
- this color for chaining
-
divide
Divides the values of this color by the given scalar value and returns the result in store.- Specified by:
dividein interfaceReadOnlyColorRGBA- Parameters:
scalar- the scalar valuestore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new color (this.r / scalar, this.g / scalar, this.b / scalar, this.a / scalar)
-
divideLocal
Internally modifies the values of this color by dividing them each by the given scalar value.- Parameters:
scalar- the scalar value- Returns:
- this color for chaining
- Throws:
ArithmeticException- if scalar is 0
-
divide
Divides the values of this color by the given scale values and returns the result in store.- Specified by:
dividein interfaceReadOnlyColorRGBA- Parameters:
scale- the scale valuesstore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new color (this.r / scale.r, this.g / scale.g, this.b / scale.b, this.a / scale.a)
-
divideLocal
Internally modifies the values of this color by dividing them each by the given scale values.- Parameters:
scale- the scale values- Returns:
- this color for chaining
-
lerp
Performs a linear interpolation between this color and the given end color, using the given scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the current value of this color and if it is closer to 1, the result will be closer to the end value.- Specified by:
lerpin interfaceReadOnlyColorRGBA- Parameters:
endColor- the end colorscalar- the scalar valuestore- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new mutable color as described above.
- Throws:
NullPointerException- if endVec is null.
-
lerpLocal
Performs a linear interpolation between this color and the given end color, using the given scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the current value of this color and if it is closer to 1, the result will be closer to the end value. The result is stored back in this color.- Parameters:
endColor- the end colorscalar- the scalar value- Returns:
- this color for chaining
- Throws:
NullPointerException- if endVec is null.
-
lerp
public static ColorRGBA lerp(ReadOnlyColorRGBA beginColor, ReadOnlyColorRGBA endColor, float scalar, ColorRGBA store) Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, if changeAmnt is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result will be closer to the end value.- Parameters:
beginColor- the begin colorendColor- the end colorscalar- the scalar as a percent.store- the color to store the result in for return. If null, a new color object is created and returned.- Returns:
- a new mutable color as described above.
- Throws:
NullPointerException- if beginVec or endVec are null.
-
lerpLocal
Performs a linear interpolation between the given begin and end colors, using the given scalar as a percent. iow, if scalar is closer to 0, the result will be closer to the begin value and if it is closer to 1, the result will be closer to the end value. The result is stored back in this color.- Parameters:
beginColor- the begin colorendColor- the end colorscalar- the scalar as a percent.- Returns:
- this color for chaining
- Throws:
NullPointerException- if beginVec or endVec are null.
-
isValid
Check a color... if it is null or its values are NaN or infinite, return false. Else return true.- Parameters:
color- the color to check- Returns:
- true or false as stated above.
-
toString
-
hashCode
public int hashCode() -
equals
-
clone
- Specified by:
clonein interfaceReadOnlyColorRGBA- Overrides:
clonein classObject
-
getClassTag
- Specified by:
getClassTagin interfaceSavable
-
write
- Specified by:
writein interfaceSavable- Throws:
IOException
-
read
- Specified by:
readin interfaceSavable- Throws:
IOException
-
readExternal
Used with serialization. Not to be called manually.- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- ObjectInput- Throws:
IOException- if something wrong happens while reading the float valuesClassNotFoundException- if a class is not found
-
writeExternal
Used with serialization. Not to be called manually.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- ObjectOutput- Throws:
IOException- exception
-
fetchTempInstance
- Returns:
- An instance of ColorRGBA that is intended for temporary use in calculations and so forth. Multiple calls to the method should return instances of this class that are not currently in use.
-
releaseTempInstance
Releases a ColorRGBA back to be used by a future call to fetchTempInstance. TAKE CARE: this ColorRGBA object should no longer have other classes referencing it or "Bad Things" will happen.- Parameters:
color- the ColorRGBA to release.
-
parseColor
Parses the given string for a color value. Currently we support hex notation - # followed by 1, 2, 3, 4, 6, or 8 chars 0-9A-F.- chars: pattern - notes
- 1: V - RGB is parsed as val/15, A=1
- 2: VA - RGB is parsed as V/15, A as A/15
- 3: RGB - RGB is parsed as R/15, G/15, B/15, A=1
- 4: RGB - RGBA are parsed as R/15, G/15, B/15, A/15
- 6: RRGGBB - RGB is parsed as RR/255, GG/255, BB/255, A=1
- 8: RRGGBBAA - RGBA is parsed as RR/255, GG/255, BB/255, AA/255
- Parameters:
colorString- the color stringstore- the object used to store the result if not null- Returns:
- the parsed color
-