Package com.formdev.flatlaf.util
Class ColorFunctions
- java.lang.Object
-
- com.formdev.flatlaf.util.ColorFunctions
-
public class ColorFunctions extends Object
Functions that modify colors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ColorFunctions.ColorFunction
static class
ColorFunctions.Fade
Set the alpha of a color.static class
ColorFunctions.HSLChange
Set the hue, saturation, luminance or alpha of a color.static class
ColorFunctions.HSLIncreaseDecrease
Increase or decrease hue, saturation, luminance or alpha of a color in the HSL color space by an absolute or relative amount.static class
ColorFunctions.Mix
Mix two colors.
-
Constructor Summary
Constructors Constructor Description ColorFunctions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
darken(Color color, float amount)
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
fade(Color color, float amount)
Set the opacity (alpha) of a color.static Color
lighten(Color color, float amount)
Increase the lightness of a color in HSL color space by an absolute amount.static float
luma(Color color)
Calculates the luma (perceptual brightness) of the given color.static Color
mix(Color color1, Color color2, float weight)
Returns a color that is a mixture of two colors.static Color
saturate(Color color, float amount)
Increase the saturation of a color in HSL color space by an absolute amount.static Color
shade(Color color, float weight)
Mix color with black, which makes the color darker.static Color
spin(Color color, float angle)
Rotate the hue angle (0-360) of a color in HSL color space in either direction.static Color
tint(Color color, float weight)
Mix color with white, which makes the color brighter.
-
-
-
Method Detail
-
lighten
public static Color lighten(Color color, float amount)
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
public static Color darken(Color color, float amount)
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
public static Color saturate(Color color, float amount)
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
public static Color desaturate(Color color, float amount)
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
public static Color spin(Color color, float angle)
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
-
fade
public static Color fade(Color color, float amount)
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
public static Color mix(Color color1, Color color2, float weight)
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
public static Color tint(Color color, float weight)
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
public static Color shade(Color color, float weight)
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
public static float luma(Color color)
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:
- https://en.wikipedia.org/wiki/Luma_(video)
-
applyFunctions
public static Color applyFunctions(Color color, ColorFunctions.ColorFunction... functions)
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.
-
-