java.lang.Object
dev.jaxydog.astral.utility.color.Rgb
Direct Known Subclasses:
Rgba

public class Rgb extends Object
Stores and allows for the manipulation of an RGB value.
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    A mask for an sRGB color's alpha value.
    static int
    A mask for an sRGB color's blue value.
    static int
    A mask for an sRGB color's green value.
    static int
    A mask for an sRGB color's red value.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rgb(double red, double green, double blue)
    Creates a new RGB value.
    Rgb(int rgb)
    Creates a new RGB value.
    Rgb(int red, int green, int blue)
    Creates a new RGB value.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the color's blue component.
    double
    Returns the color's blue component, scaled between the range [0, 1].
    float
    Returns the color's brightness.
    int
    Returns the color's green component.
    double
    Returns the color's green component, scaled between the range [0, 1].
    float
    hue()
    Returns the color's hue.
    int
    Returns the color as an integer.
    Maps each RGB color component using the given method.
    mix(Rgb other, IntBinaryOperator mix)
    Mixes two colors together by combining their color components.
    int
    red()
    Returns the color's red component.
    double
    Returns the color's red component, scaled between the range [0, 1].
    float
    Returns the color's saturation.
    withBlue(double blue)
    Sets the color's blue component.
    withBlue(int blue)
    Sets the color's blue component.
    withBrightness(float brightness)
    Sets the color's brightness.
    withGreen(double green)
    Sets the color's green component.
    withGreen(int green)
    Sets the color's green component.
    withHue(float hue)
    Sets the color's hue.
    withRed(double red)
    Sets the color's red component.
    withRed(int red)
    Sets the color's red component.
    withSaturation(float saturation)
    Sets the color's saturation.

    Methods inherited from class java.lang.Object

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

    • ALPHA_MASK

      public static int ALPHA_MASK
      A mask for an sRGB color's alpha value.
      Since:
      2.0.0
    • RED_MASK

      public static int RED_MASK
      A mask for an sRGB color's red value.
      Since:
      2.0.0
    • GREEN_MASK

      public static int GREEN_MASK
      A mask for an sRGB color's green value.
      Since:
      2.0.0
    • BLUE_MASK

      public static int BLUE_MASK
      A mask for an sRGB color's blue value.
      Since:
      2.0.0
  • Constructor Details

    • Rgb

      public Rgb(int red, int green, int blue)
      Creates a new RGB value.

      The provided values are expected to be within a range of [0, 255]. If a value exceeds this, it will be clamped.

      Parameters:
      red - The red component.
      green - The green component.
      blue - The blue component.
      Since:
      2.0.0
    • Rgb

      public Rgb(double red, double green, double blue)
      Creates a new RGB value.

      The provided values are expected to be within a range of [0, 1]. If a value exceed this, it will be clamped.

      Parameters:
      red - The red component.
      green - The green component.
      blue - The blue component.
      Since:
      2.0.0
    • Rgb

      public Rgb(int rgb)
      Creates a new RGB value.
      Parameters:
      rgb - The color as an integer.
      Since:
      2.0.0
  • Method Details

    • integer

      public int integer()
      Returns the color as an integer.
      Returns:
      The color.
      Since:
      2.0.0
    • red

      public int red()
      Returns the color's red component.
      Returns:
      The red component.
      Since:
      2.0.0
    • green

      public int green()
      Returns the color's green component.
      Returns:
      The green component.
      Since:
      2.0.0
    • blue

      public int blue()
      Returns the color's blue component.
      Returns:
      The blue component.
      Since:
      2.0.0
    • redScaled

      public double redScaled()
      Returns the color's red component, scaled between the range [0, 1].
      Returns:
      The red component.
      Since:
      2.0.0
    • greenScaled

      public double greenScaled()
      Returns the color's green component, scaled between the range [0, 1].
      Returns:
      The green component.
      Since:
      2.0.0
    • blueScaled

      public double blueScaled()
      Returns the color's blue component, scaled between the range [0, 1].
      Returns:
      The blue component.
      Since:
      2.0.0
    • hue

      public float hue()
      Returns the color's hue.

      This value will be within a range of [0, 1].

      Returns:
      The hue.
      Since:
      2.0.0
    • saturation

      public float saturation()
      Returns the color's saturation.

      This value will be within a range of [0, 1].

      Returns:
      The saturation.
      Since:
      2.0.0
    • brightness

      public float brightness()
      Returns the color's brightness.

      This value will be within a range of [0, 1].

      Returns:
      The brightness.
      Since:
      2.0.0
    • withRed

      public Rgb withRed(int red)
      Sets the color's red component.

      The given hue should be within a range of [0, 255]. If the value exceeds this, it will be clamped.

      Parameters:
      red - The new red component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withGreen

      public Rgb withGreen(int green)
      Sets the color's green component.

      The given hue should be within a range of [0, 255]. If the value exceeds this, it will be clamped.

      Parameters:
      green - The new green component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withBlue

      public Rgb withBlue(int blue)
      Sets the color's blue component.

      The given hue should be within a range of [0, 255]. If the value exceeds this, it will be clamped.

      Parameters:
      blue - The new blue component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withRed

      public Rgb withRed(double red)
      Sets the color's red component.

      The given hue should be within a range of [0, 1]. If the value exceeds this, it will be clamped.

      Parameters:
      red - The new red component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withGreen

      public Rgb withGreen(double green)
      Sets the color's green component.

      The given hue should be within a range of [0, 1]. If the value exceeds this, it will be clamped.

      Parameters:
      green - The new green component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withBlue

      public Rgb withBlue(double blue)
      Sets the color's blue component.

      The given hue should be within a range of [0, 1]. If the value exceeds this, it will be clamped.

      Parameters:
      blue - The new blue component.
      Returns:
      A new color.
      Since:
      2.0.0
    • withHue

      public Rgb withHue(float hue)
      Sets the color's hue.

      The given hue should be within a range of [0, 1]. If the value exceeds this, it will be wrapped.

      Parameters:
      hue - The new hue.
      Returns:
      A new color.
      Since:
      2.0.0
    • withSaturation

      public Rgb withSaturation(float saturation)
      Sets the color's saturation.

      The given saturation should be within a range of [0, 1]. If the value exceeds this, it will be wrapped.

      Parameters:
      saturation - The new saturation.
      Returns:
      A new color.
      Since:
      2.0.0
    • withBrightness

      public Rgb withBrightness(float brightness)
      Sets the color's brightness.

      The given brightness should be within a range of [0, 1]. If the value exceeds this, it will be wrapped.

      Parameters:
      brightness - The new brightness.
      Returns:
      A new color.
      Since:
      2.0.0
    • map

      public Rgb map(IntUnaryOperator map)
      Maps each RGB color component using the given method.
      Parameters:
      map - The mapping method.
      Returns:
      A new, mapped color.
      Since:
      2.0.0
    • mix

      public Rgb mix(Rgb other, IntBinaryOperator mix)
      Mixes two colors together by combining their color components.
      Parameters:
      other - The other color.
      mix - The mixing method.
      Returns:
      A new, mixed color.
      Since:
      2.0.0