Record Class ColorUtils
java.lang.Object
java.lang.Record
net.ixdarklord.coolcatcore.api.utils.ColorUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatalpha()Returns the normalized alpha channel (0.0–1.0).static ColorLinearly blends two colors based on the specified ratio.floatblue()Returns the normalized blue channel (0.0–1.0).static voiddebugPrint(Color color) Prints a color's RGBA components to the console for debugging.final booleanIndicates whether some other object is "equal to" this one.floatgreen()Returns the normalized green channel (0.0–1.0).final inthashCode()Returns a hash code value for this object.static ColormultiBlend(double progress, Color... colors) Blends smoothly across multiple colors according to a normalized progress value.static ColorUtilsCreates aColorUtilsinstance from a standardColor.floatred()Returns the normalized red channel (0.0–1.0).intrgb()Returns the value of thergbrecord component.static intrgbToRgba(int rgb, float alpha) Converts an RGB integer value to RGBA by applying the given alpha.static intConverts aColorto an RGBA integer by replacing its alpha component.toColor()Converts this color to a standardColorinstance.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ColorUtils
public ColorUtils(int rgb) Creates an instance of aColorUtilsrecord class.- Parameters:
rgb- the value for thergbrecord 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
-
of
-
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
-
blend
Linearly blends two colors based on the specified ratio.A ratio of
0.0returnscolor1, while a ratio of1.0returnscolor2. Intermediate values produce a smooth gradient between the two colors.- Parameters:
color1- the starting color (whenratio = 0.0)color2- the ending color (whenratio = 1.0)ratio- the blend ratio in the range[0.0, 1.0]- Returns:
- a new
Colorrepresenting the blended result
-
multiBlend
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 colorprogress = 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 moreColorinstances to interpolate between- Returns:
- the blended
Colorcorresponding to the given progress - Throws:
IllegalArgumentException- ifcolorsis null or empty
-
debugPrint
Prints a color's RGBA components to the console for debugging.- Parameters:
color- the color to print
-
toString
-
hashCode
-
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 thecomparemethod from their corresponding wrapper classes. -
rgb
public int rgb()Returns the value of thergbrecord component.- Returns:
- the value of the
rgbrecord component
-