Package arc.graphics
Class Color
java.lang.Object
arc.graphics.Color
A color class, holding the r, g, b and alpha component as floats in the range [0,1]. All methods perform clamping on the
internal values after execution.
-
Field Summary
Modifier and TypeFieldDescriptionfloat
the red, green, blue and alpha componentsstatic final Color
float
the red, green, blue and alpha componentsstatic final Color
static final float
static final int
static final Color
static final Color
static final Color
static final Color
static final float
static final int
static final Color
static final Color
static final Color
static final Color
static final Color
float
the red, green, blue and alpha componentsstatic final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
float
the red, green, blue and alpha componentsstatic final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final Color
static final float
Convenience for frequently usedWHITE.toFloatBits()
static final int
static final Color
-
Constructor Summary
ConstructorDescriptionColor()
Constructs a new Color with all components set to 0.Color
(float r, float g, float b) Constructor, sets the components of the colorColor
(float r, float g, float b, float a) Constructor, sets the components of the colorColor
(int rgba8888) Constructs a new color using the given color -
Method Summary
Modifier and TypeMethodDescriptiona
(float a) int
abgr()
Packs the color components into a 32-bit integer with the format ABGR.static int
abgr
(int r, int g, int b, int a) Packs the color components into a 32-bit integer with the format ABGR.abgr8888
(float value) Sets the Color components using the specified float value in the format ABGB8888.add
(float r, float g, float b) Adds the given color component values to this Color's values.add
(float r, float g, float b, float a) Adds the given color component values to this Color's values.Adds the given color to this color.static int
ai
(int rgba) static int
alpha
(float alpha) int
argb8888()
static int
argb8888
(float a, float r, float g, float b) argb8888
(int value) Sets the Color components using the specified integer value in the format ARGB8888.b
(float b) static int
bi
(int rgba) clamp()
Clamps this Color's components to a valid range [0 - 1]cpy()
float
Returns the difference of all the HSV components combined.boolean
static int
floatToIntColor
(float value) Converts the color from a float ABGR encoding to an int ABGR encoding.fromDouble
(double value) fromHsv
(float[] hsv) Sets RGB components using the specified Hue-Saturation-Value.fromHsv
(float h, float s, float v) Sets the RGB Color components using the specified Hue-Saturation-Value.g
(float g) static int
gi
(int rgba) static Color
grays
(float value) Creates a grayscale color.int
hashCode()
static Color
HSVtoRGB
(float h, float s, float v) Converts HSV color system to RGBstatic Color
HSVtoRGB
(float h, float s, float v, float alpha) Converts HSV to RGBstatic Color
Converts HSV color system to RGBfloat
hue()
hue
(float amount) static float
intToFloatColor
(int value) Encodes the ABGR int color as a float.inv()
Inverts this color's RGB.lerp
(float r, float g, float b, float a, float t) Linearly interpolates between this color and the target color by t which is in the range [0,1].Linearly interpolates between this color and the target color by t which is in the range [0,1].static int
luminanceAlpha
(float luminance, float alpha) mul
(float value) Multiplies RGB components of this Color with the given value.mul
(float r, float g, float b, float a) Multiplies this Color's color components by the given ones.Multiplies the this color and the given colormula
(float value) Multiplies RGBA components of this Color with the given value.mulA
(float a) static int
muli
(int rgba, float value) Multiplies a RGBA color by a float.static int
muli
(int ca, int cb) Multiplies 2 RGBA colors together.static int
packRgba
(int r, int g, int b, int a) Multiplies the RGB values by the alpha.r
(float r) rand()
randHue()
static Color
rgb
(int r, int g, int b) Creates a color from 0-255 scaled RGB values.int
rgb565()
static int
rgb565
(float r, float g, float b) rgb565
(int value) Sets the Color components using the specified integer value in the format RGB565.int
rgb888()
static int
rgb888
(float r, float g, float b) rgb888
(int value) Sets the Color components using the specified integer value in the format RGB888.int
rgba()
Shorthand forrgba8888()
.int
rgba4444()
static int
rgba4444
(float r, float g, float b, float a) rgba4444
(int value) Sets the Color components using the specified integer value in the format RGBA4444.int
rgba8888()
static int
rgba8888
(float r, float g, float b, float a) rgba8888
(int value) Sets the Color components using the specified integer value in the format RGBA8888.static int[]
RGBtoHSV
(float r, float g, float b) Converts RGB to HSV color systemstatic int[]
ConvertsColor
to HSV color systemstatic int
ri
(int rgba) float
saturation
(float amount) set
(float r, float g, float b) Sets this Color's component values.set
(float r, float g, float b, float a) Sets this Color's component values.set
(int rgba) Sets this color's component values through an integer representation.Sets this color to the given color.shiftHue
(float amount) shiftSaturation
(float amount) shiftValue
(float amount) sub
(float r, float g, float b) Subtracts the given values from this Color's component values.sub
(float r, float g, float b, float a) Subtracts the given values from this Color's component values.Subtracts the given color from this colorfloat
sum()
Returns the sum of the RGB values of this color.double
static double
toDoubleBits
(float r, float g, float b, float a) static double
toDoubleBits
(int r, int g, int b, int a) float
Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float.static float
toFloatBits
(float r, float g, float b, float a) Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float.static float
toFloatBits
(int r, int g, int b, int a) Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float.float[]
toHsv
(float[] hsv) Extract Hue-Saturation-Value.toString()
Returns the color encoded as hex string with the format RRGGBBAA.void
toString
(StringBuilder builder) float
value()
value
(float amount) static Color
Returns a new color from a hex string with the format RRGGBBAA.static Color
Returns a new color from a hex string with the format RRGGBBAA.
-
Field Details
-
white
-
lightGray
-
gray
-
darkGray
-
black
-
clear
-
whiteFloatBits
public static final float whiteFloatBitsConvenience for frequently usedWHITE.toFloatBits()
-
clearFloatBits
public static final float clearFloatBits -
blackFloatBits
public static final float blackFloatBits -
whiteRgba
public static final int whiteRgba -
clearRgba
public static final int clearRgba -
blackRgba
public static final int blackRgba -
blue
-
royal
-
slate
-
sky
-
cyan
-
teal
-
green
-
acid
-
lime
-
forest
-
olive
-
yellow
-
gold
-
goldenrod
-
orange
-
brown
-
tan
-
brick
-
red
-
scarlet
-
crimson
-
coral
-
salmon
-
pink
-
magenta
-
purple
-
violet
-
maroon
-
r
public float rthe red, green, blue and alpha components -
g
public float gthe red, green, blue and alpha components -
b
public float bthe red, green, blue and alpha components -
a
public float athe red, green, blue and alpha components
-
-
Constructor Details
-
Color
public Color()Constructs a new Color with all components set to 0. -
Color
public Color(int rgba8888) - See Also:
-
Color
public Color(float r, float g, float b, float a) Constructor, sets the components of the color- Parameters:
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha component
-
Color
public Color(float r, float g, float b) Constructor, sets the components of the color- Parameters:
r
- the red componentg
- the green componentb
- the blue component
-
Color
Constructs a new color using the given color- Parameters:
color
- the color
-
-
Method Details
-
valueOf
Returns a new color from a hex string with the format RRGGBBAA.- See Also:
-
valueOf
Returns a new color from a hex string with the format RRGGBBAA.- See Also:
-
toFloatBits
public static float toFloatBits(int r, int g, int b, int a) Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float. Note that no range checking is performed for higher performance.- Parameters:
r
- the red component, 0 - 255g
- the green component, 0 - 255b
- the blue component, 0 - 255a
- the alpha component, 0 - 255- Returns:
- the packed color as a float
- See Also:
-
toFloatBits
public static float toFloatBits(float r, float g, float b, float a) Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float.- Returns:
- the packed color as a 32-bit float
- See Also:
-
toDoubleBits
public static double toDoubleBits(float r, float g, float b, float a) -
toDoubleBits
public static double toDoubleBits(int r, int g, int b, int a) -
fromDouble
-
abgr
public static int abgr(int r, int g, int b, int a) Packs the color components into a 32-bit integer with the format ABGR. Note that no range checking is performed for higher performance.- Parameters:
r
- the red component, 0 - 255g
- the green component, 0 - 255b
- the blue component, 0 - 255a
- the alpha component, 0 - 255- Returns:
- the packed color as a 32-bit int
-
alpha
public static int alpha(float alpha) -
luminanceAlpha
public static int luminanceAlpha(float luminance, float alpha) -
rgb565
public static int rgb565(float r, float g, float b) -
rgba4444
public static int rgba4444(float r, float g, float b, float a) -
rgb888
public static int rgb888(float r, float g, float b) -
rgba8888
public static int rgba8888(float r, float g, float b, float a) -
argb8888
public static int argb8888(float a, float r, float g, float b) -
packRgba
public static int packRgba(int r, int g, int b, int a) - Returns:
- 4 0-255 RGBA components packed into an int.
-
rgb565
public int rgb565() -
rgba4444
public int rgba4444() -
rgb888
public int rgb888() -
rgba8888
public int rgba8888() -
argb8888
public int argb8888() -
rgb565
Sets the Color components using the specified integer value in the format RGB565. This is inverse to the rgb565(r, g, b) method.- Parameters:
value
- An integer color value in RGB565 format.
-
rgba4444
Sets the Color components using the specified integer value in the format RGBA4444. This is inverse to the rgba4444(r, g, b, a) method.- Parameters:
value
- An integer color value in RGBA4444 format.
-
rgb888
Sets the Color components using the specified integer value in the format RGB888. This is inverse to the rgb888(r, g, b) method.- Parameters:
value
- An integer color value in RGB888 format.
-
rgba8888
Sets the Color components using the specified integer value in the format RGBA8888. This is inverse to the rgba8888(r, g, b, a) method.- Parameters:
value
- An integer color value in RGBA8888 format.
-
argb8888
Sets the Color components using the specified integer value in the format ARGB8888. This is the inverse to the argb8888(a, r, g, b) method- Parameters:
value
- An integer color value in ARGB8888 format.
-
abgr8888
Sets the Color components using the specified float value in the format ABGB8888. -
grays
Creates a grayscale color. -
rgb
Creates a color from 0-255 scaled RGB values. -
floatToIntColor
public static int floatToIntColor(float value) Converts the color from a float ABGR encoding to an int ABGR encoding. The alpha is expanded from 0-254 in the float encoding (seeintToFloatColor(int)
) to 0-255, which means converting from int to float and back to int can be lossy. -
intToFloatColor
public static float intToFloatColor(int value) Encodes the ABGR int color as a float. The alpha is compressed to 0-254 to avoid using bits in the NaN range (seeFloat.intBitsToFloat(int)
javadocs). Rendering which uses colors encoded as floats should expand the 0-254 back to 0-255. -
rand
-
randHue
-
diff
Returns the difference of all the HSV components combined. -
rgba
public int rgba()Shorthand forrgba8888()
. -
set
Sets this color to the given color.- Parameters:
color
- the Color
-
set
-
mul
Multiplies the this color and the given color- Parameters:
color
- the color- Returns:
- this color.
-
mul
Multiplies RGB components of this Color with the given value.- Parameters:
value
- the value- Returns:
- this color
-
mula
Multiplies RGBA components of this Color with the given value.- Parameters:
value
- the value- Returns:
- this color
-
add
Adds the given color to this color.- Parameters:
color
- the color- Returns:
- this color
-
sub
Subtracts the given color from this color- Parameters:
color
- the color- Returns:
- this color
-
clamp
Clamps this Color's components to a valid range [0 - 1]- Returns:
- this Color for chaining
-
set
Sets this Color's component values.- Parameters:
r
- Red componentg
- Green componentb
- Blue componenta
- Alpha component- Returns:
- this Color for chaining
-
set
Sets this Color's component values.- Parameters:
r
- Red componentg
- Green componentb
- Blue component- Returns:
- this Color for chaining
-
set
Sets this color's component values through an integer representation.- Returns:
- this Color for chaining
-
sum
public float sum()Returns the sum of the RGB values of this color. -
add
Adds the given color component values to this Color's values.- Parameters:
r
- Red componentg
- Green componentb
- Blue componenta
- Alpha component- Returns:
- this Color for chaining
-
add
Adds the given color component values to this Color's values.- Parameters:
r
- Red componentg
- Green componentb
- Blue component- Returns:
- this Color for chaining
-
sub
Subtracts the given values from this Color's component values.- Parameters:
r
- Red componentg
- Green componentb
- Blue componenta
- Alpha component- Returns:
- this Color for chaining
-
sub
Subtracts the given values from this Color's component values.- Parameters:
r
- Red componentg
- Green componentb
- Blue component- Returns:
- this Color for chaining
-
inv
Inverts this color's RGB. -
r
-
g
-
b
-
a
-
mulA
-
mul
Multiplies this Color's color components by the given ones.- Parameters:
r
- Red componentg
- Green componentb
- Blue componenta
- Alpha component- Returns:
- this Color for chaining
-
lerp
Linearly interpolates between this color and the target color by t which is in the range [0,1]. The result is stored in this color.- Parameters:
target
- The target colort
- The interpolation coefficient- Returns:
- This color for chaining.
-
lerp
Linearly interpolates between this color and the target color by t which is in the range [0,1]. The result is stored in this color.- Parameters:
r
- The red component of the target colorg
- The green component of the target colorb
- The blue component of the target colora
- The alpha component of the target colort
- The interpolation coefficient- Returns:
- This color for chaining.
-
premultiplyAlpha
Multiplies the RGB values by the alpha. -
write
-
hue
public float hue() -
saturation
public float saturation() -
value
public float value() -
hue
-
saturation
-
value
-
shiftHue
-
shiftSaturation
-
shiftValue
-
equals
-
hashCode
public int hashCode() -
toFloatBits
public float toFloatBits()Packs the color components into a 32-bit integer with the format ABGR and then converts it to a float. Alpha is compressed from 0-255 to 0-254 to avoid using float bits in the NaN range (seeintToFloatColor(int)
).- Returns:
- the packed color as a 32-bit float
-
toDoubleBits
public double toDoubleBits() -
abgr
public int abgr()Packs the color components into a 32-bit integer with the format ABGR.- Returns:
- the packed color as a 32-bit int.
-
toString
Returns the color encoded as hex string with the format RRGGBBAA. -
toString
-
fromHsv
Sets the RGB Color components using the specified Hue-Saturation-Value. Note that HSV components are voluntary not clamped to preserve high range color and can range beyond typical values.- Parameters:
h
- The Hue in degree from 0 to 360s
- The Saturation from 0 to 1v
- The Value (brightness) from 0 to 1- Returns:
- The modified Color for chaining.
-
fromHsv
Sets RGB components using the specified Hue-Saturation-Value. This is a convenient method forfromHsv(float, float, float)
. This is the inverse oftoHsv(float[])
.- Parameters:
hsv
- The Hue, Saturation and Value components in that order.- Returns:
- The modified Color for chaining.
-
toHsv
public float[] toHsv(float[] hsv) Extract Hue-Saturation-Value. This is the inverse offromHsv(float[])
.- Parameters:
hsv
- The HSV array to be modified.- Returns:
- HSV components for chaining.
-
HSVtoRGB
Converts HSV to RGB- Parameters:
h
- hue 0-360s
- saturation 0-100v
- value 0-100alpha
- 0-1
-
HSVtoRGB
Converts HSV color system to RGB- Parameters:
h
- hue 0-360s
- saturation 0-100v
- value 0-100
-
HSVtoRGB
Converts HSV color system to RGB- Parameters:
h
- hue 0-360s
- saturation 0-100v
- value 0-100targetColor
- color that result will be stored in- Returns:
- targetColor
-
RGBtoHSV
ConvertsColor
to HSV color system- Returns:
- 3 element int array with hue (0-360), saturation (0-100) and value (0-100)
-
RGBtoHSV
public static int[] RGBtoHSV(float r, float g, float b) Converts RGB to HSV color system- Parameters:
r
- red 0-1g
- green 0-1b
- blue 0-1- Returns:
- 3 element int array with hue (0-360), saturation (0-100) and value (0-100)
-
cpy
- Returns:
- a copy of this color
-
lerp
-
ri
public static int ri(int rgba) - Returns:
- R value of a RGBA packed color.
-
gi
public static int gi(int rgba) - Returns:
- G value of a RGBA packed color.
-
bi
public static int bi(int rgba) - Returns:
- B value of a RGBA packed color.
-
ai
public static int ai(int rgba) - Returns:
- A value of a RGBA packed color.
-
muli
public static int muli(int ca, int cb) Multiplies 2 RGBA colors together. -
muli
public static int muli(int rgba, float value) Multiplies a RGBA color by a float. Alpha channels are not multiplied.
-