Package com.jme3.math
Class ColorRGBA
java.lang.Object
com.jme3.math.ColorRGBA
- All Implemented Interfaces:
Savable
,Serializable
,Cloneable
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.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfloat
The alpha component of the color.float
The blue component of the color.static final ColorRGBA
The color black (0,0,0).static final ColorRGBA
The black color with no alpha (0, 0, 0, 0).static final ColorRGBA
The color blue (0,0,1).static final ColorRGBA
The color brown (65/255, 40/255, 25/255).static final ColorRGBA
The color cyan (0,1,1).static final ColorRGBA
The color gray (.2,.2,.2).float
The green component of the color.static final ColorRGBA
The color gray (.5,.5,.5).static final ColorRGBA
The color green (0,1,0).static final ColorRGBA
The color gray (.8,.8,.8).static final ColorRGBA
The color magenta (1,0,1).static final ColorRGBA
The color orange (251/255, 130/255,0).static final ColorRGBA
The color pink (1, 0.68, 0.68).float
The red component of the color.static final ColorRGBA
The color red (1,0,0).static final ColorRGBA
The color white (1,1,1).static final ColorRGBA
The color yellow (1,1,0). -
Constructor Summary
ConstructorDescriptionConstructor instantiates a newColorRGBA
object.ColorRGBA
(float r, float g, float b, float a) Constructor instantiates a newColorRGBA
object.Copy constructor creates a newColorRGBA
object, based on a provided color.Constructor creates a newColorRGBA
object, based on a provided Vector3f, at full opacity with a 1.0 alpha value by defaultConstructor creates a newColorRGBA
object, based on a provided Vector4f. -
Method Summary
Modifier and TypeMethodDescriptionAdds each r,g,b,a of thisColorRGBA
by the corresponding r,g,b,a of the given color and returns the result as a newColorRGBA
.Adds each component to the corresponding component of the argument and returns the result (this).byte[]
Retrieves the component values of thisColorRGBA
as a four elementbyte
array in the order: r,g,b,a.int
Retrieves the component values of thisColorRGBA
as anint
in a,b,g,r order.int
Retrieves the component values of thisColorRGBA
as anint
in a,r,g,b order.int
Retrieves the component values of thisColorRGBA
as anint
in r,g,b,a order.void
clamp()
Saturate that color ensuring all channels have a value between 0 and 1clone()
Create a copy of this color.boolean
equals
returns true if thisColorRGBA
is logically equivalent to a given color.fromIntABGR
(int color) Sets the RGBA values of thisColorRGBA
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.fromIntARGB
(int color) Sets the component values of thisColorRGBA
with the given combined ARGBint
.fromIntRGBA
(int color) Sets the RGBA values of thisColorRGBA
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 thisColorRGBA
.Get the color in sRGB color space as aColorRGBA
.float
getBlue()
Retrieves the blue component value of thisColorRGBA
.float[]
getColorArray
retrieves the color values of thisColorRGBA
as a four elementfloat
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 thisColorRGBA
.float
getRed()
Retrieves the red component value of thisColorRGBA
.int
hashCode()
hashCode
returns a unique code for thisColorRGBA
based on its values.interpolateLocal
(ColorRGBA finalColor, float changeAmount) Sets thisColorRGBA
to the interpolation by changeAmount from this to the finalColor: this=(1-changeAmount)*this + changeAmount * finalColorinterpolateLocal
(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmount) Sets thisColorRGBA
to the interpolation by changeAmount from beginColor to finalColor: this=(1-changeAmount)*beginColor + changeAmount * finalColormult
(float scalar) Multiplies each r,g,b,a of thisColorRGBA
by the given scalar and returns the result as a newColorRGBA
.Multiplies each r,g,b,a of thisColorRGBA
by the corresponding r,g,b,a of the given color and returns the result as a newColorRGBA
.multLocal
(float scalar) Multiplies each r,g,b,a of thisColorRGBA
by the given scalar and returns the result (this).static ColorRGBA
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.set
(float r, float g, float b, float a) set
sets the RGBA values of thisColorRGBA
.set
sets the values of thisColorRGBA
to those set by a parameter color.set
sets the values of thisColorRGBA
to those set by a parameter Vector3f.set
sets the values of thisColorRGBA
to those set by a parameter Vector4f.setAlpha
(float value) Sets the alpha color to the specified value.setAsSrgb
(float r, float g, float b, float a) Sets the rgba channels of this color in sRGB color space.setBlue
(float value) Sets the blue color to the specified value.setGreen
(float value) Sets the green color to the specified value.setRed
(float value) Sets the red color to the specified value.float[]
toArray
(float[] floats) Saves thisColorRGBA
into the givenfloat
array.toString()
toString
returns the string representation of thisColorRGBA
.Transform thisColorRGBA
to aVector3f
using x = r, y = g, z = b.Transform thisColorRGBA
to aVector4f
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.
-
Field Details
-
Black
The color black (0,0,0). -
White
The color white (1,1,1). -
DarkGray
The color gray (.2,.2,.2). -
Gray
The color gray (.5,.5,.5). -
LightGray
The color gray (.8,.8,.8). -
Red
The color red (1,0,0). -
Green
The color green (0,1,0). -
Blue
The color blue (0,0,1). -
Yellow
The color yellow (1,1,0). -
Magenta
The color magenta (1,0,1). -
Cyan
The color cyan (0,1,1). -
Orange
The color orange (251/255, 130/255,0). -
Brown
The color brown (65/255, 40/255, 25/255). -
Pink
The color pink (1, 0.68, 0.68). -
BlackNoAlpha
The black color with no alpha (0, 0, 0, 0). -
r
public float rThe red component of the color. 0 is none and 1 is maximum red. -
g
public float gThe green component of the color. 0 is none and 1 is maximum green. -
b
public float bThe blue component of the color. 0 is none and 1 is maximum blue. -
a
public float aThe alpha component of the color. 0 is transparent and 1 is opaque.
-
-
Constructor Details
-
ColorRGBA
public ColorRGBA()Constructor instantiates a newColorRGBA
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 newColorRGBA
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 usesetAsSrgb(float, float, float, float)
- Parameters:
r
- The red component of this color.g
- The green component of thisColorRGBA
.b
- The blue component of thisColorRGBA
.a
- The alpha component of thisColorRGBA
.
-
ColorRGBA
Copy constructor creates a newColorRGBA
object, based on a provided color.- Parameters:
rgba
- TheColorRGBA
object to copy.
-
ColorRGBA
Constructor creates a newColorRGBA
object, based on a provided Vector4f.- Parameters:
vec4
- TheVector4f
object that will have its x, y, z, and w values copied to this color's r, g, b, and a values respectively.
-
ColorRGBA
Constructor creates a newColorRGBA
object, based on a provided Vector3f, at full opacity with a 1.0 alpha value by default- Parameters:
vec3
- TheVector3f
object that will have its x, y, and z values copied to this color's r, g, and b values respectively.
-
-
Method Details
-
set
set
sets the RGBA values of thisColorRGBA
. these values are assumed to be in linear space and stored as is. If you want to assign sRGB values usesetAsSrgb(float, float, float, float)
- 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
set
sets the values of thisColorRGBA
to those set by a parameter color.- Parameters:
rgba
- The color to set thisColorRGBA
to.- Returns:
- this
-
set
set
sets the values of thisColorRGBA
to those set by a parameter Vector4f.- Parameters:
vec4
- The 4 component vector that will have its x, y, z, and w values copied to thisColorRGBA
's r, g, b, and a values respectively.- Returns:
- this
-
set
set
sets the values of thisColorRGBA
to those set by a parameter Vector3f.- Parameters:
vec3
- The 3 component vector that will have its x, y, and z values copied to thisColorRGBA
's r, g, and b values respectively.- Returns:
- this
-
setRed
Sets the red color to the specified value.- Parameters:
value
- the value to set the red channel.- Returns:
- the ColorRGBA object with the modified value.
-
setGreen
Sets the green color to the specified value.- Parameters:
value
- the value to set the green channel.- Returns:
- the ColorRGBA object with the modified value.
-
setBlue
Sets the blue color to the specified value.- Parameters:
value
- the value to set the blue channel.- Returns:
- the ColorRGBA object with the modified value.
-
setAlpha
Sets the alpha color to the specified value.- Parameters:
value
- the value to set the alpha channel.- Returns:
- the ColorRGBA object with the modified value.
-
clamp
public void clamp()Saturate that color ensuring all channels have a value between 0 and 1 -
getColorArray
public float[] getColorArray()getColorArray
retrieves the color values of thisColorRGBA
as a four elementfloat
array in the order: r,g,b,a.- Returns:
- The
float
array that contains the color components.
-
getColorArray
public float[] getColorArray(float[] store) Stores the current r,g,b,a values into the given array. The given array must have a length of 4 or greater, or an array index out of bounds exception will be thrown.- Parameters:
store
- Thefloat
array to store the values into.- Returns:
- The
float
array after storage.
-
getAlpha
public float getAlpha()Retrieves the alpha component value of thisColorRGBA
.- Returns:
- The alpha component value.
-
getRed
public float getRed()Retrieves the red component value of thisColorRGBA
.- Returns:
- The red component value.
-
getBlue
public float getBlue()Retrieves the blue component value of thisColorRGBA
.- Returns:
- The blue component value.
-
getGreen
public float getGreen()Retrieves the green component value of thisColorRGBA
.- Returns:
- The green component value.
-
interpolateLocal
Sets thisColorRGBA
to the interpolation by changeAmount from this to the finalColor: this=(1-changeAmount)*this + changeAmount * finalColor- Parameters:
finalColor
- The final color to interpolate towards.changeAmount
- An amount between 0.0 - 1.0 representing a percentage change from this towards finalColor.- Returns:
- this ColorRGBA
-
interpolateLocal
Sets thisColorRGBA
to the interpolation by changeAmount from beginColor to finalColor: this=(1-changeAmount)*beginColor + changeAmount * finalColor- Parameters:
beginColor
- 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.- Returns:
- this ColorRGBA
-
randomColor
randomColor
is a utility method that generates a random opaque color.- Returns:
- a random
ColorRGBA
with an alpha set to 1.
-
mult
Multiplies each r,g,b,a of thisColorRGBA
by the corresponding r,g,b,a of the given color and returns the result as a newColorRGBA
. Used as a way of combining colors and lights.- Parameters:
c
- The color to multiply by.- Returns:
- The new
ColorRGBA
. this*c
-
mult
Multiplies each r,g,b,a of thisColorRGBA
by the given scalar and returns the result as a newColorRGBA
. Used as a way of making colors dimmer or brighter.- Parameters:
scalar
- The scalar to multiply by.- Returns:
- The new
ColorRGBA
. this*scalar
-
multLocal
Multiplies each r,g,b,a of thisColorRGBA
by the given scalar and returns the result (this). Used as a way of making colors dimmer or brighter.- Parameters:
scalar
- The scalar to multiply by.- Returns:
- this*c
-
add
Adds each r,g,b,a of thisColorRGBA
by the corresponding r,g,b,a of the given color and returns the result as a newColorRGBA
. Used as a way of combining colors and lights.- Parameters:
c
- The color to add.- Returns:
- The new
ColorRGBA
. this+c
-
addLocal
Adds each component to the corresponding component of the argument and returns the result (this). Used as a way of combining colors and lights.- Parameters:
c
- The color to add.- Returns:
- this+c
-
toString
toString
returns the string representation of thisColorRGBA
. The format of the string is:
Color[R.RRRR, G.GGGG, B.BBBB, A.AAAA] -
clone
Create a copy of this color. -
toArray
public float[] toArray(float[] floats) Saves thisColorRGBA
into the givenfloat
array.- Parameters:
floats
- Thefloat
array to take thisColorRGBA
. If null, a newfloat[4]
is created.- Returns:
- The array, with r,g,b,a float values in that order.
-
equals
equals
returns true if thisColorRGBA
is logically equivalent to a given color. That is, if all the components of the two colors are the same. False is returned otherwise. -
hashCode
public int hashCode()hashCode
returns a unique code for thisColorRGBA
based on its values. If two colors are logically equivalent, they will return the same hash code value. -
write
Serialize this color to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Parameters:
e
- (not null)- Throws:
IOException
- from the exporter
-
read
De-serialize this color from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
asBytesRGBA
public byte[] asBytesRGBA()Retrieves the component values of thisColorRGBA
as a four elementbyte
array in the order: r,g,b,a.- Returns:
- the
byte
array that contains the color components.
-
asIntARGB
public int asIntARGB()Retrieves the component values of thisColorRGBA
as anint
in a,r,g,b order. Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.- Returns:
- The integer representation of this
ColorRGBA
in a,r,g,b order.
-
asIntRGBA
public int asIntRGBA()Retrieves the component values of thisColorRGBA
as anint
in r,g,b,a order. Bits 24-31 are red, 16-23 are green, 8-15 are blue, 0-7 are alpha.- Returns:
- The integer representation of this
ColorRGBA
in r,g,b,a order.
-
asIntABGR
public int asIntABGR()Retrieves the component values of thisColorRGBA
as anint
in a,b,g,r order. Bits 24-31 are alpha, 16-23 are blue, 8-15 are green, 0-7 are red.- Returns:
- The integer representation of this
ColorRGBA
in a,b,g,r order.
-
fromIntARGB
Sets the component values of thisColorRGBA
with the given combined ARGBint
. Bits 24-31 are alpha, bits 16-23 are red, bits 8-15 are green, bits 0-7 are blue.- Parameters:
color
- The integer ARGB value used to set thisColorRGBA
.- Returns:
- this
-
fromIntRGBA
Sets the RGBA values of thisColorRGBA
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.- Parameters:
color
- The integer RGBA value used to set this object.- Returns:
- this
-
fromIntABGR
Sets the RGBA values of thisColorRGBA
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.- Parameters:
color
- The integer ABGR value used to set this object.- Returns:
- this
-
fromRGBA255
Converts a color from RGBA 255 values.- Parameters:
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.- Returns:
- the ColorRGBA equivalent of the RGBA 255 color.
-
toVector3f
Transform thisColorRGBA
to aVector3f
using x = r, y = g, z = b. The Alpha value is not used. This method is useful for shader assignments.- Returns:
- A
Vector3f
containing the RGB value of thisColorRGBA
.
-
toVector4f
Transform thisColorRGBA
to aVector4f
using x = r, y = g, z = b, w = a. This method is useful for shader assignments.- Returns:
- A
Vector4f
containing the RGBA value of thisColorRGBA
.
-
setAsSrgb
Sets the rgba channels of this color in sRGB color space. You probably want to use this method if the color is picked by the use in a color picker from a GUI. Note that the values will be gamma corrected to be stored in linear space GAMMA value is 2.2 Note that no correction will be performed on the alpha channel as it conventionally doesn't represent a color itself- Parameters:
r
- the red value in sRGB color spaceg
- the green value in sRGB color spaceb
- the blue value in sRGB color spacea
- the alpha value- Returns:
- this ColorRGBA with updated values.
-
getAsSrgb
Get the color in sRGB color space as aColorRGBA
. 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.- Returns:
- the color in sRGB color space as a ColorRGBA.
-