Class MutableColor

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

public class MutableColor extends Object implements Color
The Mmutable version of Color. Useful when you need to ensure modifications alter the instance and does not create new objects
  • Field Details

    • r

      public float r
      Components [0..1]
    • g

      public float g
      Components [0..1]
    • b

      public float b
      Components [0..1]
    • a

      public float a
      Components [0..1]
  • Constructor Details

    • MutableColor

      public MutableColor(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)
    • MutableColor

      public MutableColor(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)
    • MutableColor

      public MutableColor(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)
    • MutableColor

      public MutableColor(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

    • r

      public float r()
      Description copied from interface: Color
      Red component [0..1]
      Specified by:
      r in interface Color
    • g

      public float g()
      Description copied from interface: Color
      Green component [0..1]
      Specified by:
      g in interface Color
    • b

      public float b()
      Description copied from interface: Color
      Blue component [0..1]
      Specified by:
      b in interface Color
    • a

      public float a()
      Description copied from interface: Color
      Alpha component [0..1]
      Specified by:
      a in interface Color
    • withValues

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

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

      public MutableColor 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 MutableColor 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 MutableColor 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 MutableColor invert()
      Description copied from interface: Color
      Returns an inverted‐color version of this color (ignoring alpha).
      Specified by:
      invert in interface Color
    • grayscale

      public MutableColor 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 MutableColor 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 MutableColor 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 MutableColor r(float red)
      Description copied from interface: Color
      Sets the red value of this color.
      Specified by:
      r in interface Color
    • g

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

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

      public MutableColor 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)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object