Record Class ImmutableColor

java.lang.Object
java.lang.Record
com.stereowalker.unionlib.util.math.ImmutableColor
All Implemented Interfaces:
Color

public record ImmutableColor(float r, float g, float b, float a) extends Record implements Color
The Immutable version of Color. Useful when you need to ensure modifications do not alter your instance
  • 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

      public ImmutableColor withValues(float r, float g, float b, float a)
      Specified by:
      withValues in interface Color
    • withValues

      public ImmutableColor withValues(float r, float g, float b)
      Specified by:
      withValues in interface Color
    • lerp

      public ImmutableColor lerp(@Nonnull Color other, float t)
      Description copied from interface: Color
      Returns a new Color that is the linear interpolation between this and other.
      Specified by:
      lerp in interface Color
      Parameters:
      other - target color
      t - interpolation factor [0..1]
    • multiply

      public ImmutableColor multiply(@Nonnull Color over)
      Description copied from interface: Color
      Returns a new Color that is this color multiplied component‐wise by other.
      Specified by:
      multiply in interface Color
      Parameters:
      over - multiplier color
    • blend

      public ImmutableColor blend(@Nonnull Color over)
      Description copied from interface: Color
      Alpha‐composites over on top of this color (this = “background,” over = “foreground”).
      Specified by:
      blend in interface Color
    • invert

      public ImmutableColor invert()
      Description copied from interface: Color
      Returns an inverted‐color version of this color (ignoring alpha).
      Specified by:
      invert in interface Color
    • grayscale

      public ImmutableColor grayscale()
      Description copied from interface: Color
      Returns a grayscale version of this color, preserving alpha. Uses standard luminosity formula: gray = 0.299R + 0.587G + 0.114B.
      Specified by:
      grayscale in interface Color
    • brighten

      public ImmutableColor brighten(float factor)
      Description copied from interface: Color
      Returns a brighter version of this color by multiplying each RGB by factor (>1). Alpha is unchanged.
      Specified by:
      brighten in interface Color
    • darken

      public ImmutableColor darken(float factor)
      Description copied from interface: Color
      Returns a darker version of this color by dividing each RGB by factor (>1). Alpha is unchanged.
      Specified by:
      darken in interface Color
    • r

      public ImmutableColor r(float red)
      Description copied from interface: Color
      Sets the red value of this color.
      Specified by:
      r in interface Color
    • g

      public ImmutableColor g(float gre)
      Description copied from interface: Color
      Sets the green value of this color.
      Specified by:
      g in interface Color
    • b

      public ImmutableColor b(float blu)
      Description copied from interface: Color
      Sets the blue value of this color.
      Specified by:
      b in interface Color
    • a

      public ImmutableColor a(float alp)
      Description copied from interface: Color
      Sets the alpha of this color.
      Specified by:
      a in interface Color
    • equals

      public boolean equals(Object obj)
      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:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • 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
    • clamp01

      public static float clamp01(float v)
      Clamps a float between 0 and 1.
    • r

      public float r()
      Returns the value of the r record component.
      Specified by:
      r in interface Color
      Returns:
      the value of the r record component
    • g

      public float g()
      Returns the value of the g record component.
      Specified by:
      g in interface Color
      Returns:
      the value of the g record component
    • b

      public float b()
      Returns the value of the b record component.
      Specified by:
      b in interface Color
      Returns:
      the value of the b record component
    • a

      public float a()
      Returns the value of the a record component.
      Specified by:
      a in interface Color
      Returns:
      the value of the a record component