Class HSLColor


  • public class HSLColor
    extends java.lang.Object
    The HSLColor class provides methods to manipulate HSL (Hue, Saturation Luminance) values to create a corresponding Color object using the RGB ColorSpace.

    The HUE is the color, the Saturation is the purity of the color (with respect to grey) and Luminance is the brightness of the color (with respect to black and white)

    The Hue is specified as an angel between 0 - 360 degrees where red is 0, green is 120 and blue is 240. In between you have the colors of the rainbow. Saturation is specified as a percentage between 0 - 100 where 100 is fully saturated and 0 approaches gray. Luminance is specified as a percentage between 0 - 100 where 0 is black and 100 is white.

    In particular the HSL color space makes it easier change the Tone or Shade of a color by adjusting the luminance value.

    • Constructor Summary

      Constructors 
      Constructor Description
      HSLColor​(float[] hsl)
      Create a HSLColor object using an an array containing the individual HSL values and with a default alpha value of 1.
      HSLColor​(float[] hsl, float alpha)
      Create a HSLColor object using an an array containing the individual HSL values.
      HSLColor​(float h, float s, float l)
      Create a HSLColor object using individual HSL values and a default alpha value of 1.0.
      HSLColor​(float h, float s, float l, float alpha)
      Create a HSLColor object using individual HSL values.
      HSLColor​(java.awt.Color rgb)
      Create a HSLColor object using an RGB Color object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Color adjustHue​(float degrees)
      Create a RGB Color object based on this HSLColor with a different Hue value.
      java.awt.Color adjustLuminance​(float percent)
      Create a RGB Color object based on this HSLColor with a different Luminance value.
      java.awt.Color adjustSaturation​(float percent)
      Create a RGB Color object based on this HSLColor with a different Saturation value.
      java.awt.Color adjustShade​(float percent)
      Create a RGB Color object based on this HSLColor with a different Shade.
      java.awt.Color adjustTone​(float percent)
      Create a RGB Color object based on this HSLColor with a different Tone.
      static float[] fromRGB​(java.awt.Color color)
      Convert a RGB Color to it corresponding HSL values.
      float getAlpha()
      Get the Alpha value.
      java.awt.Color getComplementary()
      Create a RGB Color object that is the complementary color of this HSLColor.
      float[] getHSL()
      Get the HSL values.
      float getHue()
      Get the Hue value.
      float getLuminance()
      Get the Luminance value.
      java.awt.Color getRGB()
      Get the RGB Color object represented by this HDLColor.
      float getSaturation()
      Get the Saturation value.
      static java.awt.Color toRGB​(float[] hsl)
      Convert HSL values to a RGB Color with a default alpha value of 1.
      static java.awt.Color toRGB​(float[] hsl, float alpha)
      Convert HSL values to a RGB Color.
      static java.awt.Color toRGB​(float h, float s, float l)
      Convert HSL values to a RGB Color with a default alpha value of 1.
      static java.awt.Color toRGB​(float h, float s, float l, float alpha)
      Convert HSL values to a RGB Color.
      static float[] toRGB​(float h, float s, float l, float[] rgb)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HSLColor

        public HSLColor​(java.awt.Color rgb)
        Create a HSLColor object using an RGB Color object.
        Parameters:
        rgb - the RGB Color object
      • HSLColor

        public HSLColor​(float h,
                        float s,
                        float l)
        Create a HSLColor object using individual HSL values and a default alpha value of 1.0.
        Parameters:
        h - is the Hue value in degrees between 0 - 360
        s - is the Saturation percentage between 0 - 100
        l - is the Lumanance percentage between 0 - 100
      • HSLColor

        public HSLColor​(float h,
                        float s,
                        float l,
                        float alpha)
        Create a HSLColor object using individual HSL values.
        Parameters:
        h - the Hue value in degrees between 0 - 360
        s - the Saturation percentage between 0 - 100
        l - the Lumanance percentage between 0 - 100
        alpha - the alpha value between 0 - 1
      • HSLColor

        public HSLColor​(float[] hsl)
        Create a HSLColor object using an an array containing the individual HSL values and with a default alpha value of 1.
        Parameters:
        hsl - array containing HSL values
      • HSLColor

        public HSLColor​(float[] hsl,
                        float alpha)
        Create a HSLColor object using an an array containing the individual HSL values.
        Parameters:
        hsl - array containing HSL values
        alpha - the alpha value between 0 - 1
    • Method Detail

      • adjustHue

        public java.awt.Color adjustHue​(float degrees)
        Create a RGB Color object based on this HSLColor with a different Hue value. The degrees specified is an absolute value.
        Returns:
        the RGB Color object
      • adjustLuminance

        public java.awt.Color adjustLuminance​(float percent)
        Create a RGB Color object based on this HSLColor with a different Luminance value. The percent specified is an absolute value.
        Returns:
        the RGB Color object
      • adjustSaturation

        public java.awt.Color adjustSaturation​(float percent)
        Create a RGB Color object based on this HSLColor with a different Saturation value. The percent specified is an absolute value.
        Returns:
        the RGB Color object
      • adjustShade

        public java.awt.Color adjustShade​(float percent)
        Create a RGB Color object based on this HSLColor with a different Shade. Changing the shade will return a darker color. The percent specified is a relative value.
        Returns:
        the RGB Color object
      • adjustTone

        public java.awt.Color adjustTone​(float percent)
        Create a RGB Color object based on this HSLColor with a different Tone. Changing the tone will return a lighter color. The percent specified is a relative value.
        Returns:
        the RGB Color object
      • getAlpha

        public float getAlpha()
        Get the Alpha value.
        Returns:
        the Alpha value.
      • getComplementary

        public java.awt.Color getComplementary()
        Create a RGB Color object that is the complementary color of this HSLColor. This is a convenience method. The complementary color is determined by adding 180 degrees to the Hue value.
        Returns:
        the RGB Color object
      • getHue

        public float getHue()
        Get the Hue value.
        Returns:
        the Hue value.
      • getHSL

        public float[] getHSL()
        Get the HSL values.
        Returns:
        the HSL values.
      • getLuminance

        public float getLuminance()
        Get the Luminance value.
        Returns:
        the Luminance value.
      • getRGB

        public java.awt.Color getRGB()
        Get the RGB Color object represented by this HDLColor.
        Returns:
        the RGB Color object.
      • getSaturation

        public float getSaturation()
        Get the Saturation value.
        Returns:
        the Saturation value.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromRGB

        public static float[] fromRGB​(java.awt.Color color)
        Convert a RGB Color to it corresponding HSL values.
        Returns:
        an array containing the 3 HSL values.
      • toRGB

        public static java.awt.Color toRGB​(float[] hsl)
        Convert HSL values to a RGB Color with a default alpha value of 1. H (Hue) is specified as degrees in the range 0 - 360. S (Saturation) is specified as a percentage in the range 1 - 100. L (Lumanance) is specified as a percentage in the range 1 - 100.
      • toRGB

        public static java.awt.Color toRGB​(float[] hsl,
                                           float alpha)
        Convert HSL values to a RGB Color. H (Hue) is specified as degrees in the range 0 - 360. S (Saturation) is specified as a percentage in the range 1 - 100. L (Lumanance) is specified as a percentage in the range 1 - 100.
      • toRGB

        public static java.awt.Color toRGB​(float h,
                                           float s,
                                           float l)
        Convert HSL values to a RGB Color with a default alpha value of 1.
        Parameters:
        h - Hue is specified as degrees in the range 0 - 360.
        s - Saturation is specified as a percentage in the range 1 - 100.
        l - Lumanance is specified as a percentage in the range 1 - 100.
      • toRGB

        public static java.awt.Color toRGB​(float h,
                                           float s,
                                           float l,
                                           float alpha)
        Convert HSL values to a RGB Color.
        Parameters:
        h - Hue is specified as degrees in the range 0 - 360.
        s - Saturation is specified as a percentage in the range 1 - 100.
        l - Lumanance is specified as a percentage in the range 1 - 100.
        alpha - the alpha value between 0 - 1
      • toRGB

        public static float[] toRGB​(float h,
                                    float s,
                                    float l,
                                    float[] rgb)