Package nl.colorize.multimedialib.stage
Record Class ColorRGB
java.lang.Object
java.lang.Record
nl.colorize.multimedialib.stage.ColorRGB
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionalter(int deltaR, int deltaG, int deltaB) Returns a new color that adds the specified delta to this color's RGB components.intb()Returns the value of thebrecord component.final booleanIndicates whether some other object is "equal to" this one.intg()Returns the value of thegrecord component.intgetRGB()final inthashCode()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 ColorRGBParses a color from a hexadecimal color string, for example "#FF0000" for red.intr()Returns the value of therrecord component.toHex()Returns the hexadecimal color string for this color, for example "#FF0000" for red.toString()Returns a string representation of this record class.
-
Field Details
-
BLACK
-
WHITE
-
GRAY
-
RED
-
GREEN
-
BLUE
-
YELLOW
-
ORANGE
-
PURPLE
-
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
Returns the hexadecimal color string for this color, for example "#FF0000" for red. -
alter
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
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
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. -
parseHex
Parses a color from a hexadecimal color string, for example "#FF0000" for red.- Throws:
IllegalArgumentException- ifhexis 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. -
equals
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 '=='. -
r
public int r()Returns the value of therrecord component.- Returns:
- the value of the
rrecord component
-
g
public int g()Returns the value of thegrecord component.- Returns:
- the value of the
grecord component
-
b
public int b()Returns the value of thebrecord component.- Returns:
- the value of the
brecord component
-