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 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 this color in hexidecimal notation. For example, the color red (255, 0, 0) will return "#FF0000".
    • 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 hexadecimal notation. For example, parsing the string "#FF0000" will return red (255, 0, 0).
      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