Record Class ColorRGB

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.stage.ColorRGB

public record ColorRGB(int r, int g, int b) extends Record
Represents a color built out of red, green, and blue components. The color components have a value between 0 and 255, where (0, 0, 0) is black and (255, 255, 255) is white.
  • Field Summary

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

    Constructors
    Constructor
    Description
    ColorRGB(int rgba)
    Creates a color from a single RGBA value.
    ColorRGB(int r, int g, int b)
    Creates a color from the specified red, green, and blue components.
  • Method Summary

    Modifier and Type
    Method
    Description
    alter(int deltaR, int deltaG, int deltaB)
    Returns a new color that adds the specified delta to this color's RGB components.
    int
    b()
    Returns the value of the b record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    g()
    Returns the value of the g record component.
    int
     
    final int
    Returns a hash code value for this object.
    interpolate(ColorRGB target, int steps)
    Creates a list of colors that interpolate linearly between this color and the target color.
    static ColorRGB
    Parses a color from a hexadecimal color string, for example "#FF0000" for red.
    int
    r()
    Returns the value of the r record component.
    Returns the hexadecimal color string for this color, for example "#FF0000" for red.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • BLACK

      public static final ColorRGB BLACK
    • WHITE

      public static final ColorRGB WHITE
    • GRAY

      public static final ColorRGB GRAY
    • RED

      public static final ColorRGB RED
    • GREEN

      public static final ColorRGB GREEN
    • BLUE

      public static final ColorRGB BLUE
    • YELLOW

      public static final ColorRGB YELLOW
    • ORANGE

      public static final ColorRGB ORANGE
    • PURPLE

      public static final ColorRGB PURPLE
    • PINK

      public static final ColorRGB PINK
  • Constructor Details

    • ColorRGB

      public ColorRGB(int r, int g, int b)
      Creates a color from the specified red, green, and blue components.
      Throws:
      IllegalArgumentException - if one of the color components is outside the range 0-255.
    • ColorRGB

      public ColorRGB(int rgba)
      Creates a color from a single RGBA value. The value's alpha component will be ignored.
  • Method Details

    • getRGB

      public int getRGB()
    • toHex

      public String toHex()
      Returns the hexadecimal color string for this color, for example "#FF0000" for red.
    • alter

      public ColorRGB alter(int deltaR, int deltaG, int deltaB)
      Returns a new color that adds the specified delta to this color's RGB components. The resulting RGB values will be clamped to the range (0, 255), so using this method cannot lead to invalid colors.
    • interpolate

      public List<ColorRGB> interpolate(ColorRGB target, int steps)
      Creates a list of colors that interpolate linearly between this color and the target color.
      Throws:
      IllegalArgumentException - if the number of steps is not at least 2, or if the source and target colors are already identical.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • parseHex

      public static ColorRGB parseHex(String hex)
      Parses a color from a hexadecimal color string, for example "#FF0000" for red.
      Throws:
      IllegalArgumentException - if hex is not a valid color.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • r

      public int r()
      Returns the value of the r record component.
      Returns:
      the value of the r record component
    • g

      public int g()
      Returns the value of the g record component.
      Returns:
      the value of the g record component
    • b

      public int b()
      Returns the value of the b record component.
      Returns:
      the value of the b record component