Class ColorUtils
java.lang.Object
com.github.tommyettinger.textra.utils.ColorUtils
Just has methods to convert from HSL colors to RGB and back again, for hue-changing effects mainly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic inthsl2rgb(float h, float s, float l, float a)Converts the four HSLA components, each in the 0.0 to 1.0 range, to an int in RGBA8888 format.static intlerpColors(int s, int e, float change)Interpolates from the RGBA8888 int color start towards end by change.static floatrgb2hsl(float r, float g, float b, float a)Converts the four RGBA components, each in the 0.0 to 1.0 range, to an int in "HSLA format" (hue, saturation, lightness, alpha).
-
Constructor Details
-
ColorUtils
public ColorUtils()
-
-
Method Details
-
hsl2rgb
public static int hsl2rgb(float h, float s, float l, float a)Converts the four HSLA components, each in the 0.0 to 1.0 range, to an int in RGBA8888 format. I brought this over from colorful-gdx's FloatColors class. I can't recall where I got the original HSL(A) code from, but there's a strong chance it was written by cypherdare/cyphercove for their color space comparison.- Parameters:
h- hue, from 0.0 to 1.0s- saturation, from 0.0 to 1.0l- lightness, from 0.0 to 1.0a- alpha, from 0.0 to 1.0- Returns:
- an RGBA8888-format int
-
rgb2hsl
public static float rgb2hsl(float r, float g, float b, float a)Converts the four RGBA components, each in the 0.0 to 1.0 range, to an int in "HSLA format" (hue, saturation, lightness, alpha). This format is exactly like RGBA8888 but treats what would normally be red as hue, green as saturation, and blue as lightness; alpha is the same.- Parameters:
r- red, from 0.0 to 1.0g- green, from 0.0 to 1.0b- blue, from 0.0 to 1.0a- alpha, from 0.0 to 1.0- Returns:
- an "HSLA-format" int
-
lerpColors
public static int lerpColors(int s, int e, float change)Interpolates from the RGBA8888 int color start towards end by change. Both start and end should be RGBA8888 ints, and change can be between 0f (keep start) and 1f (only use end). This is a good way to reduce allocations of temporary Colors.- Parameters:
s- the starting color as a packed inte- the end/target color as a packed intchange- how much to go from start toward end, as a float between 0 and 1; higher means closer to end- Returns:
- an RGBA8888 int that represents a color between start and end
-