Record Class ImmutableColor
java.lang.Object
java.lang.Record
com.stereowalker.unionlib.util.math.ImmutableColor
- All Implemented Interfaces:
Color
The Immutable version of Color. Useful when you need to ensure modifications do not alter your instance
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionImmutableColor(float r, float g, float b) RGB constructor, alpha defaults to 1.0.ImmutableColor(float r, float g, float b, float a) Constructs a Color with given float components.ImmutableColor(int r, int g, int b) RGB constructor with ints (0–255), alpha defaults to 255.ImmutableColor(int r, int g, int b, int a) Constructs a Color with int components (0–255). -
Method Summary
Modifier and TypeMethodDescriptionfloata()Returns the value of thearecord component.a(float alp) Sets the alpha of this color.floatb()Returns the value of thebrecord component.b(float blu) Sets the blue value of this color.Alpha‐compositesoveron top of this color (this = “background,” over = “foreground”).brighten(float factor) Returns a brighter version of this color by multiplying each RGB byfactor(>1).static floatclamp01(float v) Clamps a float between 0 and 1.darken(float factor) Returns a darker version of this color by dividing each RGB byfactor(>1).booleanIndicates whether some other object is "equal to" this one.floatg()Returns the value of thegrecord component.g(float gre) Sets the green value of this color.Returns a grayscale version of this color, preserving alpha.inthashCode()Returns a hash code value for this object.invert()Returns an inverted‐color version of this color (ignoring alpha).Returns a new Color that is the linear interpolation between this andother.Returns a new Color that is this color multiplied component‐wise byother.floatr()Returns the value of therrecord component.r(float red) Sets the red value of this color.toString()Returns a string representation of this record class.withValues(float r, float g, float b) withValues(float r, float g, float b, float a) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.stereowalker.unionlib.util.math.Color
a, b, blend, brighten, colorEquals, colorHashCode, colorToString, darken, g, getAlphaInt, getBlueInt, getGreenInt, getRedInt, grayscale, invert, lerp, multiply, r, toCMYK, toHexRGBString, toHSL, toHSLA, toHSV, toImmutable, toIntARGB, toIntRGB, toIntRGBA, toMutable
-
Constructor Details
-
ImmutableColor
public ImmutableColor(float r, float g, float b, float a) Constructs a Color with given float components. Each value is clamped to [0,1].- Parameters:
r- red (0.0–1.0)g- green (0.0–1.0)b- blue (0.0–1.0)a- alpha (0.0–1.0)
-
ImmutableColor
public ImmutableColor(int r, int g, int b, int a) Constructs a Color with int components (0–255). Values are clamped internally.- Parameters:
r- red (0–255)g- green (0–255)b- blue (0–255)a- alpha (0–255)
-
ImmutableColor
public ImmutableColor(float r, float g, float b) RGB constructor, alpha defaults to 1.0.- Parameters:
r- red (0.0–1.0)g- green (0.0–1.0)b- blue (0.0–1.0)
-
ImmutableColor
public ImmutableColor(int r, int g, int b) RGB constructor with ints (0–255), alpha defaults to 255.- Parameters:
r- red (0–255)g- green (0–255)b- blue (0–255)
-
-
Method Details
-
withValues
- Specified by:
withValuesin interfaceColor
-
withValues
- Specified by:
withValuesin interfaceColor
-
lerp
Description copied from interface:ColorReturns a new Color that is the linear interpolation between this andother. -
multiply
Description copied from interface:ColorReturns a new Color that is this color multiplied component‐wise byother. -
blend
Description copied from interface:ColorAlpha‐compositesoveron top of this color (this = “background,” over = “foreground”). -
invert
Description copied from interface:ColorReturns an inverted‐color version of this color (ignoring alpha). -
grayscale
Description copied from interface:ColorReturns a grayscale version of this color, preserving alpha. Uses standard luminosity formula: gray = 0.299R + 0.587G + 0.114B. -
brighten
Description copied from interface:ColorReturns a brighter version of this color by multiplying each RGB byfactor(>1). Alpha is unchanged. -
darken
Description copied from interface:ColorReturns a darker version of this color by dividing each RGB byfactor(>1). Alpha is unchanged. -
r
Description copied from interface:ColorSets the red value of this color. -
g
Description copied from interface:ColorSets the green value of this color. -
b
Description copied from interface:ColorSets the blue value of this color. -
a
Description copied from interface:ColorSets the alpha of this color. -
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 '=='. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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. -
clamp01
public static float clamp01(float v) Clamps a float between 0 and 1. -
r
public float r()Returns the value of therrecord component. -
g
public float g()Returns the value of thegrecord component. -
b
public float b()Returns the value of thebrecord component. -
a
public float a()Returns the value of thearecord component.
-