Class ColorFunctions

java.lang.Object
com.formdev.flatlaf.util.ColorFunctions

public class ColorFunctions extends Object
Functions that modify colors.
  • Constructor Details

    • ColorFunctions

      public ColorFunctions()
  • Method Details

    • 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 color
      amount - 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 color
      amount - 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 color
      amount - 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 color
      amount - 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 color
      angle - the number of degrees to rotate (in range -360 - 360)
      Returns:
      new color
      Since:
      2
    • hslIncreaseDecrease

      private static Color hslIncreaseDecrease(Color color, float amount, int hslIndex, boolean increase)
    • fade

      public static Color fade(Color color, float amount)
      Set the opacity (alpha) of a color.
      Parameters:
      color - base color
      amount - 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 to color2 by invoking this method multiple times with growing weight (from 0 to 1).

      Parameters:
      color1 - first color
      color2 - second color
      weight - 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 as mix(java.awt.Color, java.awt.Color, float)(Color.white, color, weight).
      Parameters:
      color - second color
      weight - 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 as mix(java.awt.Color, java.awt.Color, float)(Color.black, color, weight).
      Parameters:
      color - second color
      weight - 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:
    • gammaCorrection

      private static float gammaCorrection(float value)
    • 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.