Package com.formdev.flatlaf.util
Class ColorFunctions
java.lang.Object
com.formdev.flatlaf.util.ColorFunctions
Functions that modify colors.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
Set the alpha of a color.static class
Set the hue, saturation, luminance or alpha of a color.static class
Increase or decrease hue, saturation, luminance or alpha of a color in the HSL color space by an absolute or relative amount.static class
Mix two colors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Color
applyFunctions
(Color color, ColorFunctions.ColorFunction... functions) Applies the given color functions to the given color and returns the new color.static float
clamp
(float value) Clamps the given value between 0 and 100.static Color
Decrease the lightness of a color in HSL color space by an absolute amount.static Color
desaturate
(Color color, float amount) Decrease the saturation of a color in HSL color space by an absolute amount.static Color
Set the opacity (alpha) of a color.private static float
gammaCorrection
(float value) private static Color
hslIncreaseDecrease
(Color color, float amount, int hslIndex, boolean increase) static Color
Increase the lightness of a color in HSL color space by an absolute amount.static float
Calculates the luma (perceptual brightness) of the given color.static Color
Returns a color that is a mixture of two colors.static Color
Increase the saturation of a color in HSL color space by an absolute amount.static Color
Mix color with black, which makes the color darker.static Color
Rotate the hue angle (0-360) of a color in HSL color space in either direction.static Color
Mix color with white, which makes the color brighter.
-
Constructor Details
-
ColorFunctions
public ColorFunctions()
-
-
Method Details
-
lighten
Increase the lightness of a color in HSL color space by an absolute amount.Consider using
tint(Color, float)
as alternative.- Parameters:
color
- base coloramount
- the amount (in range 0-1) that is added to the lightness- Returns:
- new color
- Since:
- 2
-
darken
Decrease the lightness of a color in HSL color space by an absolute amount.Consider using
shade(Color, float)
as alternative.- Parameters:
color
- base coloramount
- the amount (in range 0-1) that is subtracted from the lightness- Returns:
- new color
- Since:
- 2
-
saturate
Increase the saturation of a color in HSL color space by an absolute amount.- Parameters:
color
- base coloramount
- the amount (in range 0-1) that is added to the saturation- Returns:
- new color
- Since:
- 2
-
desaturate
Decrease the saturation of a color in HSL color space by an absolute amount.- Parameters:
color
- base coloramount
- the amount (in range 0-1) that is subtracted from the saturation- Returns:
- new color
- Since:
- 2
-
spin
Rotate the hue angle (0-360) of a color in HSL color space in either direction.- Parameters:
color
- base colorangle
- the number of degrees to rotate (in range -360 - 360)- Returns:
- new color
- Since:
- 2
-
hslIncreaseDecrease
-
fade
Set the opacity (alpha) of a color.- Parameters:
color
- base coloramount
- the amount (in range 0-1) of the new opacity- Returns:
- new color
- Since:
- 3
-
mix
Returns a color that is a mixture of two colors.This can be used to animate a color change from
color1
tocolor2
by invoking this method multiple times with growingweight
(from 0 to 1).- Parameters:
color1
- first colorcolor2
- second colorweight
- the weight (in range 0-1) to mix the two colors. Larger weight uses more of first color, smaller weight more of second color.- Returns:
- mixture of colors
-
tint
Mix color with white, which makes the color brighter. This is the same asmix(java.awt.Color, java.awt.Color, float)
(Color.white, color, weight)
.- Parameters:
color
- second colorweight
- the weight (in range 0-1) to mix the two colors. Larger weight uses more of first color, smaller weight more of second color.- Returns:
- mixture of colors
- Since:
- 2
-
shade
Mix color with black, which makes the color darker. This is the same asmix(java.awt.Color, java.awt.Color, float)
(Color.black, color, weight)
.- Parameters:
color
- second colorweight
- the weight (in range 0-1) to mix the two colors. Larger weight uses more of first color, smaller weight more of second color.- Returns:
- mixture of colors
- Since:
- 2
-
luma
Calculates the luma (perceptual brightness) of the given color.Uses SMPTE C / Rec. 709 coefficients, as recommended in WCAG 2.0.
- Parameters:
color
- a color- Returns:
- the luma (in range 0-1)
- Since:
- 2
- See Also:
-
gammaCorrection
private static float gammaCorrection(float value) -
applyFunctions
Applies the given color functions to the given color and returns the new color. -
clamp
public static float clamp(float value) Clamps the given value between 0 and 100.
-