java.lang.Object
io.github.vampirestudios.vampirelib.utils.Color

public class Color extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Color(float r, float g, float b)
     
    Color(int rgb)
     
    Color(int r, int g, int b)
     
    Color(int r, int g, int b, int a)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new Color that is a brighter version of this Color.
    Creates a new Color that is a darker version of this Color.
    int
     
    int
     
    int
    Gets the chroma value, which is related to the length of the vector in projected (hexagonal) space.
    int
     
    int
     
    static Color
    getHSBColor(float h, float s, float b)
    Creates a Color object based on the specified values for the HSB color model.
    float
    Gets the saturation for this color based on chrominance and HSL luma.
    float
    Gets the saturation for this color based on chrominance and HSV Value
    int
    Gets the HSV/HSL Hue, which is the angle around the color hexagon (or circle)
    int
    Gets the HSL Lightness, or average light intensity, of this color
    int
    Gets the HSL Luma, or perceptual brightness, of this color
    int
     
    int
    Gets the HSV Value, which is just the largest component in the color
    static int
    HSBtoRGB(float hue, float saturation, float brightness)
    Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
    static int[]
    intToRgb(int color)
     
    static float[]
    RGBtoHSB(int r, int g, int b, float[] hsbvals)
    Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WHITE

      public static final Color WHITE
  • Constructor Details

    • Color

      public Color(int r, int g, int b, int a)
    • Color

      public Color(int rgb)
    • Color

      public Color(int r, int g, int b)
    • Color

      public Color(float r, float g, float b)
  • Method Details

    • intToRgb

      public static int[] intToRgb(int color)
    • HSBtoRGB

      public static int HSBtoRGB(float hue, float saturation, float brightness)
      Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.

      The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

      The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value that is the same format used by the method getRGB. This integer can be supplied as an argument to the Color constructor that takes a single integer argument.

      Parameters:
      hue - the hue component of the color
      saturation - the saturation of the color
      brightness - the brightness of the color
      Returns:
      the RGB value of the color with the indicated hue, saturation, and brightness.
      Since:
      JDK1.0
      See Also:
    • RGBtoHSB

      public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
      Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

      If the hsbvals argument is null, then a new array is allocated to return the result. Otherwise, the method returns the array hsbvals, with the values put into that array.

      Parameters:
      r - the red component of the color
      g - the green component of the color
      b - the blue component of the color
      hsbvals - the array used to return the three HSB values, or null
      Returns:
      an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
      Since:
      JDK1.0
      See Also:
    • getHSBColor

      public static Color getHSBColor(float h, float s, float b)
      Creates a Color object based on the specified values for the HSB color model.

      The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

      Parameters:
      h - the hue component
      s - the saturation of the color
      b - the brightness of the color
      Returns:
      a Color object with the specified hue, saturation, and brightness.
      Since:
      JDK1.0
    • getColor

      public int getColor()
    • getRed

      public int getRed()
    • getGreen

      public int getGreen()
    • getBlue

      public int getBlue()
    • getAlpha

      public int getAlpha()
    • getChroma

      public int getChroma()
      Gets the chroma value, which is related to the length of the vector in projected (hexagonal) space.
    • getHue

      public int getHue()
      Gets the HSV/HSL Hue, which is the angle around the color hexagon (or circle)
    • getLightness

      public int getLightness()
      Gets the HSL Lightness, or average light intensity, of this color
    • getLuma

      public int getLuma()
      Gets the HSL Luma, or perceptual brightness, of this color
    • getValue

      public int getValue()
      Gets the HSV Value, which is just the largest component in the color
    • getHSVSaturation

      public float getHSVSaturation()
      Gets the saturation for this color based on chrominance and HSV Value
    • getHSLSaturation

      public float getHSLSaturation()
      Gets the saturation for this color based on chrominance and HSL luma.
    • brighter

      public Color brighter()
      Creates a new Color that is a brighter version of this Color.

      This method applies an arbitrary scale factor to each of the three RGB components of this Color to create a brighter version of this Color. The alpha value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

      Returns:
      a new Color object that is a brighter version of this Color with the same alpha value.
      Since:
      JDK1.0
      See Also:
    • darker

      public Color darker()
      Creates a new Color that is a darker version of this Color.

      This method applies an arbitrary scale factor to each of the three RGB components of this Color to create a darker version of this Color. The alpha value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

      Returns:
      a new Color object that is a darker version of this Color with the same alpha value.
      Since:
      JDK1.0
      See Also: