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 stored in Linear color space. An alpha value determines is
transparency.Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
ColorRGBA |
add(ColorRGBA c)
Adds each r,g,b,a of this
ColorRGBA by the corresponding
r,g,b,a of the given color and returns the result as a new ColorRGBA . |
ColorRGBA |
addLocal(ColorRGBA c)
Adds each component to the corresponding component of the argument
and returns the result (this).
|
byte[] |
asBytesRGBA()
Retrieves the component values of this
ColorRGBA as
a four element byte array in the order: r,g,b,a. |
int |
asIntABGR()
Retrieves the component values of this
ColorRGBA as an
int in a,b,g,r order. |
int |
asIntARGB()
Retrieves the component values of this
ColorRGBA as an
int in a,r,g,b order. |
int |
asIntRGBA()
Retrieves the component values of this
ColorRGBA as an
int in r,g,b,a order. |
void |
clamp()
Saturate that color ensuring all channels have a value between 0 and 1
|
ColorRGBA |
clone()
Create a copy of this color.
|
boolean |
equals(java.lang.Object o)
equals returns true if this ColorRGBA is logically equivalent
to a given color. |
ColorRGBA |
fromIntABGR(int color)
Sets the RGBA values of this
ColorRGBA with the given combined ABGR value
Bits 24-31 are alpha, bits 16-23 are blue, bits 8-15 are green, bits 0-7 are red. |
ColorRGBA |
fromIntARGB(int color)
Sets the component values of this
ColorRGBA with the given
combined ARGB int . |
ColorRGBA |
fromIntRGBA(int color)
Sets the RGBA values of this
ColorRGBA with the given combined RGBA value
Bits 24-31 are red, bits 16-23 are green, bits 8-15 are blue, bits 0-7 are alpha. |
static ColorRGBA |
fromRGBA255(int r,
int g,
int b,
int a)
Converts a color from RGBA 255 values.
|
float |
getAlpha()
Retrieves the alpha component value of this
ColorRGBA . |
ColorRGBA |
getAsSrgb()
Get the color in sRGB color space as a
ColorRGBA . |
float |
getBlue()
Retrieves the blue component value of this
ColorRGBA . |
float[] |
getColorArray()
getColorArray retrieves the color values of this
ColorRGBA as a four element float array in the
order: r,g,b,a. |
float[] |
getColorArray(float[] store)
Stores the current r,g,b,a values into the given array.
|
float |
getGreen()
Retrieves the green component value of this
ColorRGBA . |
float |
getRed()
Retrieves the red component value of this
ColorRGBA . |
int |
hashCode()
hashCode returns a unique code for this ColorRGBA based
on its values. |
ColorRGBA |
interpolateLocal(ColorRGBA beginColor,
ColorRGBA finalColor,
float changeAmount)
Sets this
ColorRGBA to the interpolation by changeAmount from
beginColor to finalColor:
this=(1-changeAmount)*beginColor + changeAmount * finalColor |
ColorRGBA |
interpolateLocal(ColorRGBA finalColor,
float changeAmount)
Sets this
ColorRGBA to the interpolation by changeAmount from
this to the finalColor:
this=(1-changeAmount)*this + changeAmount * finalColor |
ColorRGBA |
mult(ColorRGBA c)
Multiplies each r,g,b,a of this
ColorRGBA by the corresponding
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
ColorRGBA by the given scalar and
returns the result as a new ColorRGBA . |
ColorRGBA |
multLocal(float scalar)
Multiplies each r,g,b,a of this
ColorRGBA by the given scalar and
returns the result (this). |
static ColorRGBA |
randomColor()
randomColor is a utility method that generates a random
opaque color. |
void |
read(JmeImporter importer)
De-serialize this color from the specified importer, for example when
loading from a J3O file.
|
ColorRGBA |
set(ColorRGBA rgba)
set sets the values of this ColorRGBA to those
set by a parameter color. |
ColorRGBA |
set(float r,
float g,
float b,
float a)
set sets the RGBA values of this ColorRGBA . |
ColorRGBA |
setAlpha(float value)
Sets the alpha color to the specified value.
|
ColorRGBA |
setAsSrgb(float r,
float g,
float b,
float a)
Sets the rgba channels of this color in sRGB color space.
|
ColorRGBA |
setBlue(float value)
Sets the blue color to the specified value.
|
ColorRGBA |
setGreen(float value)
Sets the green color to the specified value.
|
ColorRGBA |
setRed(float value)
Sets the red color to the specified value.
|
float[] |
toArray(float[] floats)
Saves this
ColorRGBA into the given float array. |
java.lang.String |
toString()
toString returns the string representation of this ColorRGBA . |
Vector3f |
toVector3f()
Transform this
ColorRGBA to a Vector3f using
x = r, y = g, z = b. |
Vector4f |
toVector4f()
Transform this
ColorRGBA to a Vector4f using
x = r, y = g, z = b, w = a. |
void |
write(JmeExporter e)
Serialize this color to the specified exporter, for example when
saving to a J3O file.
|
public static final ColorRGBA Black
public static final ColorRGBA White
public static final ColorRGBA DarkGray
public static final ColorRGBA Gray
public static final ColorRGBA LightGray
public static final ColorRGBA Red
public static final ColorRGBA Green
public static final ColorRGBA Blue
public static final ColorRGBA Yellow
public static final ColorRGBA Magenta
public static final ColorRGBA Cyan
public static final ColorRGBA Orange
public static final ColorRGBA Brown
public static final ColorRGBA Pink
public static final ColorRGBA BlackNoAlpha
public float r
public float g
public float b
public float a
public ColorRGBA()
ColorRGBA
object. This
color is the default "white" with all values 1.public ColorRGBA(float r, float g, float b, float a)
ColorRGBA
object. The
values are defined as passed parameters.
these values are assumed to be in linear space and stored as is.
If you want to assign sRGB values use
setAsSrgb(float, float, float, float)
r
- The red component of this color.g
- The green component of this ColorRGBA
.b
- The blue component of this ColorRGBA
.a
- The alpha component of this ColorRGBA
.public ColorRGBA(ColorRGBA rgba)
ColorRGBA
object, based on
a provided color.rgba
- The ColorRGBA
object to copy.public ColorRGBA set(float r, float g, float b, float a)
set
sets the RGBA values of this ColorRGBA
.
these values are assumed to be in linear space and stored as is.
If you want to assign sRGB values use
setAsSrgb(float, float, float, float)
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.public ColorRGBA set(ColorRGBA rgba)
set
sets the values of this ColorRGBA
to those
set by a parameter color.rgba
- The color to set this ColorRGBA
to.public ColorRGBA setRed(float value)
value
- the value to set the red channel.public ColorRGBA setGreen(float value)
value
- the value to set the green channel.public ColorRGBA setBlue(float value)
value
- the value to set the blue channel.public ColorRGBA setAlpha(float value)
value
- the value to set the alpha channel.public void clamp()
public float[] getColorArray()
getColorArray
retrieves the color values of this
ColorRGBA
as a four element float
array in the
order: r,g,b,a.float
array that contains the color components.public float[] getColorArray(float[] store)
store
- The float
array to store the values into.float
array after storage.public float getAlpha()
ColorRGBA
.public float getRed()
ColorRGBA
.public float getBlue()
ColorRGBA
.public float getGreen()
ColorRGBA
.public ColorRGBA interpolateLocal(ColorRGBA finalColor, float changeAmount)
ColorRGBA
to the interpolation by changeAmount from
this to the finalColor:
this=(1-changeAmount)*this + changeAmount * finalColorfinalColor
- The final color to interpolate towards.changeAmount
- An amount between 0.0 - 1.0 representing a percentage
change from this towards finalColor.public ColorRGBA interpolateLocal(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmount)
ColorRGBA
to the interpolation by changeAmount from
beginColor to finalColor:
this=(1-changeAmount)*beginColor + changeAmount * finalColorbeginColor
- The beginning color (changeAmount=0).finalColor
- The final color to interpolate towards (changeAmount=1).changeAmount
- An amount between 0.0 - 1.0 representing a percentage
change from beginColor towards finalColor.public static ColorRGBA randomColor()
randomColor
is a utility method that generates a random
opaque color.ColorRGBA
with an alpha set to 1.public ColorRGBA mult(ColorRGBA c)
ColorRGBA
by the corresponding
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.c
- The color to multiply by.ColorRGBA
. this*cpublic ColorRGBA mult(float scalar)
ColorRGBA
by the given scalar and
returns the result as a new ColorRGBA
.
Used as a way of making colors dimmer or brighter.scalar
- The scalar to multiply by.ColorRGBA
. this*scalarpublic ColorRGBA multLocal(float scalar)
ColorRGBA
by the given scalar and
returns the result (this).
Used as a way of making colors dimmer or brighter.scalar
- The scalar to multiply by.public ColorRGBA add(ColorRGBA c)
ColorRGBA
by the corresponding
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.c
- The color to add.ColorRGBA
. this+cpublic ColorRGBA addLocal(ColorRGBA c)
c
- The color to add.public java.lang.String toString()
toString
returns the string representation of this ColorRGBA
.
The format of the string is:toString
in class java.lang.Object
ColorRGBA
.public ColorRGBA clone()
clone
in class java.lang.Object
public float[] toArray(float[] floats)
ColorRGBA
into the given float
array.floats
- The float
array to take this ColorRGBA
.
If null, a new float[4]
is created.public boolean equals(java.lang.Object o)
equals
returns true if this ColorRGBA
is logically equivalent
to a given color. That is, if all the components of the two colors are the same.
False is returned otherwise.equals
in class java.lang.Object
o
- The object to compare against.public int hashCode()
hashCode
returns a unique code for this ColorRGBA
based
on its values. If two colors are logically equivalent, they will return
the same hash code value.hashCode
in class java.lang.Object
ColorRGBA
.public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter importer) throws java.io.IOException
public byte[] asBytesRGBA()
ColorRGBA
as
a four element byte
array in the order: r,g,b,a.byte
array that contains the color components.public int asIntARGB()
ColorRGBA
as an
int
in a,r,g,b order.
Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.ColorRGBA
in a,r,g,b order.public int asIntRGBA()
ColorRGBA
as an
int
in r,g,b,a order.
Bits 24-31 are red, 16-23 are green, 8-15 are blue, 0-7 are alpha.ColorRGBA
in r,g,b,a order.public int asIntABGR()
ColorRGBA
as an
int
in a,b,g,r order.
Bits 24-31 are alpha, 16-23 are blue, 8-15 are green, 0-7 are red.ColorRGBA
in a,b,g,r order.public ColorRGBA fromIntARGB(int color)
ColorRGBA
with the given
combined ARGB int
.
Bits 24-31 are alpha, bits 16-23 are red, bits 8-15 are green, bits 0-7 are blue.color
- The integer ARGB value used to set this ColorRGBA
.public ColorRGBA fromIntRGBA(int color)
ColorRGBA
with the given combined RGBA value
Bits 24-31 are red, bits 16-23 are green, bits 8-15 are blue, bits 0-7 are alpha.color
- The integer RGBA value used to set this object.public ColorRGBA fromIntABGR(int color)
ColorRGBA
with the given combined ABGR value
Bits 24-31 are alpha, bits 16-23 are blue, bits 8-15 are green, bits 0-7 are red.color
- The integer ABGR value used to set this object.public static ColorRGBA fromRGBA255(int r, int g, int b, int a)
r
- the red value in 0-255 range.g
- the green value in 0-255 range.b
- the blue value in 0-255 range.a
- the alpha value in 0-255 range.public Vector3f toVector3f()
ColorRGBA
to a Vector3f
using
x = r, y = g, z = b. The Alpha value is not used.
This method is useful for shader assignments.Vector3f
containing the RGB value of this ColorRGBA
.public Vector4f toVector4f()
ColorRGBA
to a Vector4f
using
x = r, y = g, z = b, w = a.
This method is useful for shader assignments.Vector4f
containing the RGBA value of this ColorRGBA
.public ColorRGBA setAsSrgb(float r, float g, float b, float a)
r
- the red value in sRGB color spaceg
- the green value in sRGB color spaceb
- the blue value in sRGB color spacea
- the alpha valuepublic ColorRGBA getAsSrgb()
ColorRGBA
.
Note that linear values stored in the ColorRGBA will be gamma corrected
and returned as a ColorRGBA.
The x attribute will be fed with the r channel in sRGB space.
The y attribute will be fed with the g channel in sRGB space.
The z attribute will be fed with the b channel in sRGB space.
The w attribute will be fed with the a channel.
Note that no correction will be performed on the alpha channel as it
conventionally doesn't represent a color itself.