Package arc.graphics

Class Color

java.lang.Object
arc.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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
    the red, green, blue and alpha components
    static final Color
     
    float
    the red, green, blue and alpha components
    static 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 components
    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
     
    static final Color
     
    float
    the red, green, blue and alpha components
    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 float
    Convenience for frequently used WHITE.toFloatBits()
    static final int
     
    static final Color
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Color with all components set to 0.
    Color(float r, float g, float b)
    Constructor, sets the components of the color
    Color(float r, float g, float b, float a)
    Constructor, sets the components of the color
    Color(int rgba8888)
     
    Color(Color color)
    Constructs a new color using the given color
  • Method Summary

    Modifier and Type
    Method
    Description
    a(float a)
     
    int
    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.
    add(Color color)
    Adds the given color to this color.
    static int
    ai(int rgba)
     
    static int
    alpha(float alpha)
     
    int
     
    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)
     
    Clamps this Color's components to a valid range [0 - 1]
    cpy()
     
    float
    diff(Color other)
    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
     
    static Color
    HSVtoRGB(float h, float s, float v)
    Converts HSV color system to RGB
    static Color
    HSVtoRGB(float h, float s, float v, float alpha)
    Converts HSV to RGB
    static Color
    HSVtoRGB(float h, float s, float v, Color targetColor)
    Converts HSV color system to RGB
    float
    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].
    lerp(Color[] colors, float s)
     
    lerp(Color target, 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)
     
    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.
    mul(Color color)
    Multiplies the this color and the given color
    mula(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)
     
     
     
    static Color
    rgb(int r, int g, int b)
    Creates a color from 0-255 scaled RGB values.
    int
     
    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
     
    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
    Shorthand for rgba8888().
    int
     
    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
     
    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 system
    static int[]
    Converts Color to HSV color system
    static 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.
    set(Color color)
    Sets this color to the given color.
    set(Vec3 vec)
     
    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.
    sub(Color color)
    Subtracts the given color from this color
    float
    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.
    Returns the color encoded as hex string with the format RRGGBBAA.
    void
     
    float
     
    value(float amount)
     
    static Color
    valueOf(Color color, String hex)
    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.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • white

      public static final Color white
    • lightGray

      public static final Color lightGray
    • gray

      public static final Color gray
    • darkGray

      public static final Color darkGray
    • black

      public static final Color black
    • clear

      public static final Color clear
    • whiteFloatBits

      public static final float whiteFloatBits
      Convenience for frequently used WHITE.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

      public static final Color blue
    • royal

      public static final Color royal
    • slate

      public static final Color slate
    • sky

      public static final Color sky
    • cyan

      public static final Color cyan
    • teal

      public static final Color teal
    • green

      public static final Color green
    • acid

      public static final Color acid
    • lime

      public static final Color lime
    • forest

      public static final Color forest
    • olive

      public static final Color olive
    • yellow

      public static final Color yellow
    • gold

      public static final Color gold
    • goldenrod

      public static final Color goldenrod
    • orange

      public static final Color orange
    • brown

      public static final Color brown
    • tan

      public static final Color tan
    • brick

      public static final Color brick
    • red

      public static final Color red
    • scarlet

      public static final Color scarlet
    • crimson

      public static final Color crimson
    • coral

      public static final Color coral
    • salmon

      public static final Color salmon
    • pink

      public static final Color pink
    • magenta

      public static final Color magenta
    • purple

      public static final Color purple
    • violet

      public static final Color violet
    • maroon

      public static final Color maroon
    • 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 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 component
      g - the green component
      b - the blue component
      a - the alpha component
    • Color

      public Color(float r, float g, float b)
      Constructor, sets the components of the color
      Parameters:
      r - the red component
      g - the green component
      b - the blue component
    • Color

      public Color(Color color)
      Constructs a new color using the given color
      Parameters:
      color - the color
  • Method Details

    • valueOf

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

      public static Color valueOf(Color color, String hex)
      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 - 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:
    • 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

      public Color fromDouble(double value)
    • 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 - 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)
    • 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

      public Color rgb565(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:
      value - An integer color value in RGB565 format.
    • rgba4444

      public Color rgba4444(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:
      value - An integer color value in RGBA4444 format.
    • rgb888

      public Color rgb888(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:
      value - An integer color value in RGB888 format.
    • rgba8888

      public Color rgba8888(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:
      value - An integer color value in RGBA8888 format.
    • argb8888

      public Color argb8888(int value)
      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

      public Color abgr8888(float value)
      Sets the Color components using the specified float value in the format ABGB8888.
    • grays

      public static Color grays(float value)
      Creates a grayscale color.
    • rgb

      public static Color rgb(int r, int g, int b)
      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 (see intToFloatColor(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 (see Float.intBitsToFloat(int) javadocs). Rendering which uses colors encoded as floats should expand the 0-254 back to 0-255.
    • rand

      public Color rand()
    • randHue

      public Color randHue()
    • diff

      public float diff(Color other)
      Returns the difference of all the HSV components combined.
    • rgba

      public int rgba()
      Shorthand for rgba8888().
    • set

      public Color set(Color color)
      Sets this color to the given color.
      Parameters:
      color - the Color
    • set

      public Color set(Vec3 vec)
    • 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 RGB components of this Color with the given value.
      Parameters:
      value - the value
      Returns:
      this color
    • mula

      public Color mula(float value)
      Multiplies RGBA 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(float r, float g, float b)
      Sets this Color's component values.
      Parameters:
      r - Red component
      g - Green component
      b - Blue 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
    • sum

      public float sum()
      Returns the sum of the RGB values of this color.
    • 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
    • add

      public Color add(float r, float g, float b)
      Adds the given color component values to this Color's values.
      Parameters:
      r - Red component
      g - Green component
      b - Blue 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
    • sub

      public Color sub(float r, float g, float b)
      Subtracts the given values from this Color's component values.
      Parameters:
      r - Red component
      g - Green component
      b - Blue component
      Returns:
      this Color for chaining
    • inv

      public Color inv()
      Inverts this color's RGB.
    • r

      public Color r(float r)
    • g

      public Color g(float g)
    • b

      public Color b(float b)
    • a

      public Color a(float a)
    • mulA

      public Color mulA(float a)
    • 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.
    • write

      public Color write(Color to)
    • hue

      public float hue()
    • saturation

      public float saturation()
    • value

      public float value()
    • hue

      public Color hue(float amount)
    • saturation

      public Color saturation(float amount)
    • value

      public Color value(float amount)
    • shiftHue

      public Color shiftHue(float amount)
    • shiftSaturation

      public Color shiftSaturation(float amount)
    • shiftValue

      public Color shiftValue(float amount)
    • 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. Alpha is compressed from 0-255 to 0-254 to avoid using float bits in the NaN range (see intToFloatColor(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

      public String toString()
      Returns the color encoded as hex string with the format RRGGBBAA.
      Overrides:
      toString in class Object
    • toString

      public void toString(StringBuilder builder)
    • fromHsv

      public Color fromHsv(float h, float s, float v)
      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 360
      s - The Saturation from 0 to 1
      v - The Value (brightness) from 0 to 1
      Returns:
      The modified Color for chaining.
    • fromHsv

      public Color fromHsv(float[] hsv)
      Sets RGB components using the specified Hue-Saturation-Value. This is a convenient method for fromHsv(float, float, float). This is the inverse of toHsv(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 of fromHsv(float[]).
      Parameters:
      hsv - The HSV array to be modified.
      Returns:
      HSV components for chaining.
    • HSVtoRGB

      public static Color HSVtoRGB(float h, float s, float v, float alpha)
      Converts HSV to RGB
      Parameters:
      h - hue 0-360
      s - saturation 0-100
      v - value 0-100
      alpha - 0-1
    • HSVtoRGB

      public static Color HSVtoRGB(float h, float s, float v)
      Converts HSV color system to RGB
      Parameters:
      h - hue 0-360
      s - saturation 0-100
      v - value 0-100
    • HSVtoRGB

      public static Color HSVtoRGB(float h, float s, float v, Color targetColor)
      Converts HSV color system to RGB
      Parameters:
      h - hue 0-360
      s - saturation 0-100
      v - value 0-100
      targetColor - color that result will be stored in
      Returns:
      targetColor
    • RGBtoHSV

      public static int[] RGBtoHSV(Color c)
      Converts Color 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-1
      g - green 0-1
      b - blue 0-1
      Returns:
      3 element int array with hue (0-360), saturation (0-100) and value (0-100)
    • cpy

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

      public Color lerp(Color[] colors, float s)
    • 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.