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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
b()
Returns the value of theb
record component.final boolean
Indicates whether some other object is "equal to" this one.int
g()
Returns the value of theg
record component.int
getRGB()
final int
hashCode()
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 hexadecimal notation.int
r()
Returns the value of ther
record component.toHex()
Returns this color in hexidecimal notation.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 this color in hexidecimal notation. For example, the color red (255, 0, 0) will return "#FF0000". -
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 hexadecimal notation. For example, parsing the string "#FF0000" will return red (255, 0, 0).- Throws:
IllegalArgumentException
- ifhex
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. -
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 ther
record component.- Returns:
- the value of the
r
record component
-
g
public int g()Returns the value of theg
record component.- Returns:
- the value of the
g
record component
-
b
public int b()Returns the value of theb
record component.- Returns:
- the value of the
b
record component
-