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
FieldsModifier and TypeFieldDescriptionfloatThe alpha component of the color.floatThe blue component of the color.static final ColorRGBAThe color black (0,0,0).static final ColorRGBAThe black color with no alpha (0, 0, 0, 0).static final ColorRGBAThe color blue (0,0,1).static final ColorRGBAThe color brown (65/255, 40/255, 25/255).static final ColorRGBAThe color cyan (0,1,1).static final ColorRGBAThe color gray (.2,.2,.2).floatThe green component of the color.static final ColorRGBAThe color gray (.5,.5,.5).static final ColorRGBAThe color green (0,1,0).static final ColorRGBAThe color gray (.8,.8,.8).static final ColorRGBAThe color magenta (1,0,1).static final ColorRGBAThe color orange (251/255, 130/255,0).static final ColorRGBAThe color pink (1, 0.68, 0.68).floatThe red component of the color.static final ColorRGBAThe color red (1,0,0).static final ColorRGBAThe color white (1,1,1).static final ColorRGBAThe color yellow (1,1,0). -
Constructor Summary
ConstructorsConstructorDescriptionConstructor instantiates a newColorRGBAobject.ColorRGBA(float r, float g, float b, float a) Constructor instantiates a newColorRGBAobject.Copy constructor creates a newColorRGBAobject, based on a provided color.Constructor creates a newColorRGBAobject, based on a provided Vector3f, at full opacity with a 1.0 alpha value by defaultConstructor creates a newColorRGBAobject, based on a provided Vector4f. -
Method Summary
Modifier and TypeMethodDescriptionAdds each r,g,b,a of thisColorRGBAby 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 thisColorRGBAas a four elementbytearray in the order: r,g,b,a.intRetrieves the component values of thisColorRGBAas anintin a,b,g,r order.intRetrieves the component values of thisColorRGBAas anintin a,r,g,b order.intRetrieves the component values of thisColorRGBAas anintin r,g,b,a order.voidclamp()Saturate that color ensuring all channels have a value between 0 and 1clone()Create a copy of this color.booleanequalsreturns true if thisColorRGBAis logically equivalent to a given color.fromIntABGR(int color) Sets the RGBA values of thisColorRGBAwith 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 thisColorRGBAwith the given combined ARGBint.fromIntRGBA(int color) Sets the RGBA values of thisColorRGBAwith 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 ColorRGBAfromRGBA255(int r, int g, int b, int a) Converts a color from RGBA 255 values.floatgetAlpha()Retrieves the alpha component value of thisColorRGBA.Get the color in sRGB color space as aColorRGBA.floatgetBlue()Retrieves the blue component value of thisColorRGBA.float[]getColorArrayretrieves the color values of thisColorRGBAas a four elementfloatarray in the order: r,g,b,a.float[]getColorArray(float[] store) Stores the current r,g,b,a values into the given array.floatgetGreen()Retrieves the green component value of thisColorRGBA.floatgetRed()Retrieves the red component value of thisColorRGBA.inthashCode()hashCodereturns a unique code for thisColorRGBAbased on its values.interpolateLocal(ColorRGBA finalColor, float changeAmount) Sets thisColorRGBAto the interpolation by changeAmount from this to the finalColor: this=(1-changeAmount)*this + changeAmount * finalColorinterpolateLocal(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmount) Sets thisColorRGBAto the interpolation by changeAmount from beginColor to finalColor: this=(1-changeAmount)*beginColor + changeAmount * finalColormult(float scalar) Multiplies each r,g,b,a of thisColorRGBAby the given scalar and returns the result as a newColorRGBA.Multiplies each r,g,b,a of thisColorRGBAby 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 thisColorRGBAby the given scalar and returns the result (this).static ColorRGBArandomColoris a utility method that generates a random opaque color.voidread(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) setsets the RGBA values of thisColorRGBA.setsets the values of thisColorRGBAto those set by a parameter color.setsets the values of thisColorRGBAto those set by a parameter Vector3f.setsets the values of thisColorRGBAto 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 thisColorRGBAinto the givenfloatarray.toString()toStringreturns the string representation of thisColorRGBA.Transform thisColorRGBAto aVector3fusing x = r, y = g, z = b.Transform thisColorRGBAto aVector4fusing x = r, y = g, z = b, w = a.voidwrite(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 newColorRGBAobject. This color is the default "white" with all values 1. -
ColorRGBA
public ColorRGBA(float r, float g, float b, float a) Constructor instantiates a newColorRGBAobject. 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 newColorRGBAobject, based on a provided color.- Parameters:
rgba- TheColorRGBAobject to copy.
-
ColorRGBA
Constructor creates a newColorRGBAobject, based on a provided Vector4f.- Parameters:
vec4- TheVector4fobject 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 newColorRGBAobject, based on a provided Vector3f, at full opacity with a 1.0 alpha value by default- Parameters:
vec3- TheVector3fobject that will have its x, y, and z values copied to this color's r, g, and b values respectively.
-
-
Method Details
-
set
setsets 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
setsets the values of thisColorRGBAto those set by a parameter color.- Parameters:
rgba- The color to set thisColorRGBAto.- Returns:
- this
-
set
setsets the values of thisColorRGBAto 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
setsets the values of thisColorRGBAto 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()getColorArrayretrieves the color values of thisColorRGBAas a four elementfloatarray in the order: r,g,b,a.- Returns:
- The
floatarray 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- Thefloatarray to store the values into.- Returns:
- The
floatarray 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 thisColorRGBAto 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 thisColorRGBAto 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
randomColoris a utility method that generates a random opaque color.- Returns:
- a random
ColorRGBAwith an alpha set to 1.
-
mult
Multiplies each r,g,b,a of thisColorRGBAby 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 thisColorRGBAby 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 thisColorRGBAby 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 thisColorRGBAby 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
toStringreturns 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 thisColorRGBAinto the givenfloatarray.- Parameters:
floats- Thefloatarray to take thisColorRGBA. If null, a newfloat[4]is created.- Returns:
- The array, with r,g,b,a float values in that order.
-
equals
equalsreturns true if thisColorRGBAis 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()hashCodereturns a unique code for thisColorRGBAbased 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:
writein 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:
readin interfaceSavable- Parameters:
importer- (not null)- Throws:
IOException- from the importer
-
asBytesRGBA
public byte[] asBytesRGBA()Retrieves the component values of thisColorRGBAas a four elementbytearray in the order: r,g,b,a.- Returns:
- the
bytearray that contains the color components.
-
asIntARGB
public int asIntARGB()Retrieves the component values of thisColorRGBAas anintin 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
ColorRGBAin a,r,g,b order.
-
asIntRGBA
public int asIntRGBA()Retrieves the component values of thisColorRGBAas anintin 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
ColorRGBAin r,g,b,a order.
-
asIntABGR
public int asIntABGR()Retrieves the component values of thisColorRGBAas anintin 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
ColorRGBAin a,b,g,r order.
-
fromIntARGB
Sets the component values of thisColorRGBAwith 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 thisColorRGBAwith 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 thisColorRGBAwith 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 thisColorRGBAto aVector3fusing x = r, y = g, z = b. The Alpha value is not used. This method is useful for shader assignments.- Returns:
- A
Vector3fcontaining the RGB value of thisColorRGBA.
-
toVector4f
Transform thisColorRGBAto aVector4fusing x = r, y = g, z = b, w = a. This method is useful for shader assignments.- Returns:
- A
Vector4fcontaining 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.
-