Package graphics

Class Color

java.lang.Object
graphics.Color

public class Color extends Object

Azurite

Represents a 4-channel color of either RGBA or HSLA type, with some helper functions to convert an RGBA to HSLA, or vice versa. This Class also contains some predefined colors, a random color generator, and some OpenGL-related helper functions.
See Also:
  • Field Details

    • TYPE_RGBA

      public static final int TYPE_RGBA
      See Also:
    • TYPE_HSLA

      public static final int TYPE_HSLA
      See Also:
    • random

      public static Random random
    • WHITE

      public static Color WHITE
    • BLACK

      public static Color BLACK
    • RED

      public static Color RED
    • DARK_RED

      public static Color DARK_RED
    • GREEN

      public static Color GREEN
    • BLUE

      public static Color BLUE
    • DARK_BLUE

      public static Color DARK_BLUE
    • DIRTY_BLUE

      public static Color DIRTY_BLUE
    • PINK

      public static Color PINK
    • CYAN

      public static Color CYAN
    • YELLOW

      public static Color YELLOW
    • PURPLE

      public static Color PURPLE
    • SILVER

      public static Color SILVER
    • GRAY

      public static Color GRAY
    • MAROON

      public static Color MAROON
    • OLIVE

      public static Color OLIVE
    • DARK_GREEN

      public static Color DARK_GREEN
    • TEAL

      public static Color TEAL
    • BROWN

      public static Color BROWN
    • FIREBRICK

      public static Color FIREBRICK
    • CRIMSON

      public static Color CRIMSON
    • r

      public float r
      Red component for this color. Range: 0-255
    • g

      public float g
      Green component for this color. Range: 0-255
    • b

      public float b
      Blue component for this color. Range: 0-255
    • a

      public float a
      Alpha component for this color. Range: 0-255
  • Constructor Details

    • Color

      public Color(float pr, float pg, float pb, float pa)
      Creates new color with specified rgba values
      Parameters:
      pr - initial red value
      pg - initial green value
      pb - initial blue value
      pa - initial alpha value
    • Color

      public Color(float pr, float pg, float pb)
      Creates new color with specified rgb values
      Parameters:
      pr - initial red value
      pg - initial green value
      pb - initial blue value
    • Color

      public Color(float c)
      Creates new color with specified value for rgb
      Parameters:
      c - value for red, green and blue
  • Method Details

    • randomColor

      public static Color randomColor()
      Returns:
      random Color
    • getColor

      public static Color getColor(float x, float y, float z, float a, int inputType)
      Create a new color.
      Parameters:
      x - the first component
      y - the second component
      z - the third component
      a - the alpha value
      inputType - whether the input values are RGBA or HSLA
      Returns:
      a RGBA Color representing the input
    • decode

      public static Color decode(String colorCode)
      Decode a rgb color code into a Color
      Parameters:
      colorCode - the color code
      Returns:
      a valid rgb color
      See Also:
    • toVec4f

      public org.joml.Vector4f toVec4f()
      Returns a Vector4f with rgba as xyzw
    • toNormalizedVec4f

      public org.joml.Vector4f toNormalizedVec4f()
      Get the Normalized Vector4f for this color. Used mostly in OpenGL
    • toNormalizedVec3f

      public org.joml.Vector3f toNormalizedVec3f()
      Get the Normalized Vector3f for this color. Used mostly in OpenGL
    • fromNormalized

      public Color fromNormalized()
      Turn a Color with normalised values to a color with values from 0-255
    • equals

      public boolean equals(Object c)
      Check if colors are equal
      Overrides:
      equals in class Object
    • setAlpha

      public void setAlpha(float value)
      Set Alpha for this color
    • toHSLColor

      public HSLColor toHSLColor()
      Convert this RGB Color to a HSLColor using HSLColor.toHSLA(float[])
      Returns:
      a HSLColor representing the same color
    • setValue

      public void setValue(char type, float value)
      Set a component of this color to a value
      Parameters:
      type - can be one of r, g, b, a
      value - value to set the component to