com.badlogic.gdx.graphics
Class Color

java.lang.Object
  extended by com.badlogic.gdx.graphics.Color

public class Color
extends Object

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.

Author:
mzechner

Field Summary
 float a
          the red, green, blue and alpha components
 float b
          the red, green, blue and alpha components
static Color BLACK
           
static Color BLUE
           
static Color CLEAR
           
static Color CYAN
           
static Color DARK_GRAY
           
 float g
          the red, green, blue and alpha components
static Color GRAY
           
static Color GREEN
           
static Color LIGHT_GRAY
           
static Color MAGENTA
           
static Color ORANGE
           
static Color PINK
           
 float r
          the red, green, blue and alpha components
static Color RED
           
static Color tmp
          Deprecated. 
static Color WHITE
           
static Color YELLOW
           
 
Constructor Summary
Color()
          Constructs a new Color with all components set to 0.
Color(Color color)
          Constructs a new color using the given color
Color(float r, float g, float b, float a)
          Constructor, sets the components of the color
Color(int rgba8888)
           
 
Method Summary
 Color add(Color color)
          Adds the given color to this color.
 Color add(float r, float g, float b, float a)
          Adds the given color component values to this Color's values.
static int alpha(float alpha)
           
 Color clamp()
          Clamps this Color's components to a valid range [0 - 1]
 Color cpy()
           
 boolean equals(Object o)
           
 int hashCode()
           
 Color lerp(Color target, float t)
          Linearly interpolates between this color and the target color by t which is in the range [0,1].
 Color 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].
static int luminanceAlpha(float luminance, float alpha)
           
 Color mul(Color color)
          Multiplies the this color and the given color
 Color mul(float value)
          Multiplies all components of this Color with the given value.
 Color mul(float r, float g, float b, float a)
          Multiplies this Color's color components by the given ones.
 Color premultiplyAlpha()
          Multiplies the RGB values by the alpha.
static int rgb565(Color color)
           
static int rgb565(float r, float g, float b)
           
static void rgb565ToColor(Color color, int value)
          Sets the Color components using the specified integer value in the format RGB565.
static int rgb888(Color color)
           
static int rgb888(float r, float g, float b)
           
static void rgb888ToColor(Color color, int value)
          Sets the Color components using the specified integer value in the format RGB888.
static int rgba4444(Color color)
           
static int rgba4444(float r, float g, float b, float a)
           
static void rgba4444ToColor(Color color, int value)
          Sets the Color components using the specified integer value in the format RGBA4444.
static int rgba8888(Color color)
           
static int rgba8888(float r, float g, float b, float a)
           
static void rgba8888ToColor(Color color, int value)
          Sets the Color components using the specified integer value in the format RGBA8888.
 Color set(Color color)
          Sets this color to the given color.
 Color set(float r, float g, float b, float a)
          Sets this Color's component values.
 Color set(int rgba)
          Sets this color's component values through an integer representation.
 Color sub(Color color)
          Subtracts the given color from this color
 Color sub(float r, float g, float b, float a)
          Subtracts the given values from this Color's component values.
 Color tmp()
          Returns a temporary copy of this color.
 float toFloatBits()
          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.
 int toIntBits()
          Packs the color components into a 32-bit integer with the format ABGR.
static int toIntBits(int r, int g, int b, int a)
          Packs the color components into a 32-bit integer with the format ABGR.
 String toString()
          Returns the color encoded as hex string with the format RRGGBBAA.
static Color valueOf(String hex)
          Returns a new color from a hex string with the format RRGGBBAA.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLEAR

public static final Color CLEAR

WHITE

public static final Color WHITE

BLACK

public static final Color BLACK

RED

public static final Color RED

GREEN

public static final Color GREEN

BLUE

public static final Color BLUE

LIGHT_GRAY

public static final Color LIGHT_GRAY

GRAY

public static final Color GRAY

DARK_GRAY

public static final Color DARK_GRAY

PINK

public static final Color PINK

ORANGE

public static final Color ORANGE

YELLOW

public static final Color YELLOW

MAGENTA

public static final Color MAGENTA

CYAN

public static final Color CYAN

tmp

@Deprecated
public static Color tmp
Deprecated. 

r

public float r
the red, green, blue and alpha components


g

public float g
the red, green, blue and alpha components


b

public float b
the red, green, blue and alpha components


a

public float a
the red, green, blue and alpha components

Constructor Detail

Color

public Color()
Constructs a new Color with all components set to 0.


Color

public Color(int rgba8888)
See Also:
rgba8888ToColor(Color, int)

Color

public Color(float r,
             float g,
             float b,
             float a)
Constructor, sets the components of the color

Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component

Color

public Color(Color color)
Constructs a new color using the given color

Parameters:
color - the color
Method Detail

set

public Color set(Color color)
Sets this color to the given color.

Parameters:
color - the Color

mul

public Color mul(Color color)
Multiplies the this color and the given color

Parameters:
color - the color
Returns:
this color.

mul

public Color mul(float value)
Multiplies all components of this Color with the given value.

Parameters:
value - the value
Returns:
this color

add

public Color add(Color color)
Adds the given color to this color.

Parameters:
color - the color
Returns:
this color

sub

public Color sub(Color color)
Subtracts the given color from this color

Parameters:
color - the color
Returns:
this color

clamp

public Color clamp()
Clamps this Color's components to a valid range [0 - 1]

Returns:
this Color for chaining

set

public Color set(float r,
                 float g,
                 float b,
                 float a)
Sets this Color's component values.

Parameters:
r - Red component
g - Green component
b - Blue component
a - Alpha component
Returns:
this Color for chaining

set

public Color set(int rgba)
Sets this color's component values through an integer representation.

Returns:
this Color for chaining
See Also:
rgba8888ToColor(Color, int)

add

public Color add(float r,
                 float g,
                 float b,
                 float a)
Adds the given color component values to this Color's values.

Parameters:
r - Red component
g - Green component
b - Blue component
a - Alpha component
Returns:
this Color for chaining

sub

public Color sub(float r,
                 float g,
                 float b,
                 float a)
Subtracts the given values from this Color's component values.

Parameters:
r - Red component
g - Green component
b - Blue component
a - Alpha component
Returns:
this Color for chaining

mul

public Color mul(float r,
                 float g,
                 float b,
                 float a)
Multiplies this Color's color components by the given ones.

Parameters:
r - Red component
g - Green component
b - Blue component
a - Alpha component
Returns:
this Color for chaining

lerp

public Color lerp(Color target,
                  float t)
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 color
t - The interpolation coefficient
Returns:
This color for chaining.

lerp

public Color 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]. The result is stored in this color.

Parameters:
r - The red component of the target color
g - The green component of the target color
b - The blue component of the target color
a - The alpha component of the target color
t - The interpolation coefficient
Returns:
This color for chaining.

premultiplyAlpha

public Color premultiplyAlpha()
Multiplies the RGB values by the alpha.


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toFloatBits

public float toFloatBits()
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:
NumberUtils.intToFloatColor(int)

toIntBits

public int toIntBits()
Packs the color components into a 32-bit integer with the format ABGR.

Returns:
the packed color as a 32-bit int.

toString

public String toString()
Returns the color encoded as hex string with the format RRGGBBAA.

Overrides:
toString in class Object

valueOf

public static Color valueOf(String hex)
Returns a new color from a hex string with the format RRGGBBAA.

See Also:
toString()

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 - 255
g - the green component, 0 - 255
b - the blue component, 0 - 255
a - the alpha component, 0 - 255
Returns:
the packed color as a float
See Also:
NumberUtils.intToFloatColor(int)

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:
NumberUtils.intToFloatColor(int)

toIntBits

public static int toIntBits(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 - 255
g - the green component, 0 - 255
b - the blue component, 0 - 255
a - 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)

rgb565

public static int rgb565(Color color)

rgba4444

public static int rgba4444(Color color)

rgb888

public static int rgb888(Color color)

rgba8888

public static int rgba8888(Color color)

rgb565ToColor

public static void rgb565ToColor(Color color,
                                 int value)
Sets the Color components using the specified integer value in the format RGB565. This is inverse to the rgb565(r, g, b) method.

Parameters:
color - The Color to be modified.
value - An integer color value in RGB565 format.

rgba4444ToColor

public static void rgba4444ToColor(Color color,
                                   int value)
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:
color - The Color to be modified.
value - An integer color value in RGBA4444 format.

rgb888ToColor

public static void rgb888ToColor(Color color,
                                 int value)
Sets the Color components using the specified integer value in the format RGB888. This is inverse to the rgb888(r, g, b) method.

Parameters:
color - The Color to be modified.
value - An integer color value in RGB888 format.

rgba8888ToColor

public static void rgba8888ToColor(Color color,
                                   int value)
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:
color - The Color to be modified.
value - An integer color value in RGBA8888 format.

tmp

public Color tmp()
Returns a temporary copy of this color. This is not thread safe, do not save a reference to this instance.

Returns:
a temporary copy of this color

cpy

public Color cpy()
Returns:
a copy of this color


Copyright © 2014. All Rights Reserved.