Record Class ColorUtils

java.lang.Object
java.lang.Record
net.ixdarklord.coolcatcore.api.utils.ColorUtils

public record ColorUtils(int rgb) extends Record
Utility record representing and manipulating colors in RGBA format.

Provides methods for extracting normalized channels, blending, and converting between RGB/RGBA integer and Color representations.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ColorUtils(int rgb)
    Creates an instance of a ColorUtils record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Returns the normalized alpha channel (0.0–1.0).
    static Color
    blend(Color color1, Color color2, double ratio)
    Linearly blends two colors based on the specified ratio.
    float
    Returns the normalized blue channel (0.0–1.0).
    static void
    Prints a color's RGBA components to the console for debugging.
    final boolean
    Indicates whether some other object is "equal to" this one.
    float
    Returns the normalized green channel (0.0–1.0).
    final int
    Returns a hash code value for this object.
    static Color
    multiBlend(double progress, Color... colors)
    Blends smoothly across multiple colors according to a normalized progress value.
    static ColorUtils
    of(Color color)
    Creates a ColorUtils instance from a standard Color.
    float
    red()
    Returns the normalized red channel (0.0–1.0).
    int
    rgb()
    Returns the value of the rgb record component.
    static int
    rgbToRgba(int rgb, float alpha)
    Converts an RGB integer value to RGBA by applying the given alpha.
    static int
    rgbToRgba(Color color, float alpha)
    Converts a Color to an RGBA integer by replacing its alpha component.
    Converts this color to a standard Color instance.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ColorUtils

      public ColorUtils(int rgb)
      Creates an instance of a ColorUtils record class.
      Parameters:
      rgb - the value for the rgb record component
  • Method Details

    • alpha

      public float alpha()
      Returns the normalized alpha channel (0.0–1.0).
    • red

      public float red()
      Returns the normalized red channel (0.0–1.0).
    • green

      public float green()
      Returns the normalized green channel (0.0–1.0).
    • blue

      public float blue()
      Returns the normalized blue channel (0.0–1.0).
    • toColor

      public Color toColor()
      Converts this color to a standard Color instance.
      Returns:
      a Color based on this rgb value (including alpha)
    • of

      public static ColorUtils of(Color color)
      Creates a ColorUtils instance from a standard Color.
      Parameters:
      color - the Color to convert
      Returns:
      a new ColorUtils wrapping the color's RGBA value
    • rgbToRgba

      public static int rgbToRgba(int rgb, float alpha)
      Converts an RGB integer value to RGBA by applying the given alpha.
      Parameters:
      rgb - the RGB color value (without alpha)
      alpha - the alpha value (0.0–1.0)
      Returns:
      the RGBA color integer
    • rgbToRgba

      public static int rgbToRgba(Color color, float alpha)
      Converts a Color to an RGBA integer by replacing its alpha component.
      Parameters:
      color - the input Color
      alpha - the new alpha value (0.0–1.0)
      Returns:
      the RGBA color integer with the adjusted alpha
    • blend

      public static Color blend(Color color1, Color color2, double ratio)
      Linearly blends two colors based on the specified ratio.

      A ratio of 0.0 returns color1, while a ratio of 1.0 returns color2. Intermediate values produce a smooth gradient between the two colors.

      Parameters:
      color1 - the starting color (when ratio = 0.0)
      color2 - the ending color (when ratio = 1.0)
      ratio - the blend ratio in the range [0.0, 1.0]
      Returns:
      a new Color representing the blended result
    • multiBlend

      public static Color multiBlend(double progress, Color... colors)
      Blends smoothly across multiple colors according to a normalized progress value.

      This method interpolates between consecutive colors in the provided array. For example, with three colors and progress = 0.5, the result will be approximately halfway between the first and second colors.

      Behavior:

      • progress = 0.0 → returns the first color
      • progress = 1.0 → returns the last color
      • Values in between produce smooth transitions
      Parameters:
      progress - the normalized blend progress, clamped to [0.0, 1.0]
      colors - one or more Color instances to interpolate between
      Returns:
      the blended Color corresponding to the given progress
      Throws:
      IllegalArgumentException - if colors is null or empty
    • debugPrint

      public static void debugPrint(Color color)
      Prints a color's RGBA components to the console for debugging.
      Parameters:
      color - the color to print
    • toString

      public final 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
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • rgb

      public int rgb()
      Returns the value of the rgb record component.
      Returns:
      the value of the rgb record component