Class HSLColor
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 angle 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
ConstructorDescriptionHSLColor
(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.Create a HSLColor object using an RGB Color object. -
Method Summary
Modifier and TypeMethodDescriptionadjustHue
(float degrees) Create a RGB Color object based on this HSLColor with a different Hue value.adjustLuminance
(float percent) Create a RGB Color object based on this HSLColor with a different Luminance value.adjustSaturation
(float percent) Create a RGB Color object based on this HSLColor with a different Saturation value.adjustShade
(float percent) Create a RGB Color object based on this HSLColor with a different Shade.adjustTone
(float percent) Create a RGB Color object based on this HSLColor with a different Tone.static Color
changeLuminance
(Color c, int luminanceOffset) Get a new color by adjusting the luminance of Color c.static float[]
Convert a RGB Color to it corresponding HSL values.float
getAlpha()
Get the Alpha value.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
Get the Luminance value.getRGB()
Get the RGB Color object represented by this HDLColor.float
Get the Saturation value.static Color
toRGB
(float[] hsl) Convert HSL values to a RGB Color with a default alpha value of 1.static Color
toRGB
(float[] hsl, float alpha) Convert HSL values to a RGB Color.static Color
toRGB
(float h, float s, float l) Convert HSL values to a RGB Color with a default alpha value of 1.static Color
toRGB
(float h, float s, float l, float alpha) Convert HSL values to a RGB Color.toString()
-
Constructor Details
-
HSLColor
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 - 360s
- is the Saturation percentage between 0 - 100l
- 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 - 360s
- the Saturation percentage between 0 - 100l
- the Lumanance percentage between 0 - 100alpha
- 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 valuesalpha
- the alpha value between 0 - 1
-
-
Method Details
-
adjustHue
Create a RGB Color object based on this HSLColor with a different Hue value.The degrees specified is an absolute value.
- Parameters:
degrees
- - the Hue value between 0 - 360- Returns:
- the RGB Color object
-
adjustLuminance
Create a RGB Color object based on this HSLColor with a different Luminance value.The percent specified is an absolute value.
- Parameters:
percent
- - the Luminance value between 0 - 100- Returns:
- the RGB Color object
-
adjustSaturation
Create a RGB Color object based on this HSLColor with a different Saturation value. The percent specified is an absolute value.- Parameters:
percent
- - the Saturation value between 0 - 100- Returns:
- the RGB Color object
-
adjustShade
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.
- Parameters:
percent
- - the value between 0 - 100- Returns:
- the RGB Color object
-
adjustTone
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.
- Parameters:
percent
- - the value between 0 - 100- Returns:
- the RGB Color object
-
getAlpha
public float getAlpha()Get the Alpha value.- Returns:
- the Alpha value.
-
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 [0-100]
-
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 [0-100]
-
toString
-
fromRGB
Convert a RGB Color to it corresponding HSL values.- Returns:
- an array containing the 3 HSL values.
-
changeLuminance
Get a new color by adjusting the luminance of Color c.For example a luminanceOffset of 3 with c=GREEN will return a little brighter GREEN.
- Parameters:
c
-luminanceOffset
- The value in the range [-100; 100] to be added to c's luminance. The resulting luminance is maintained in the [0-100] range.- Returns:
-
toRGB
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.- Parameters:
hsl
- an array containing the 3 HSL values- Returns:
- the RGB Color object
-
toRGB
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.- Parameters:
hsl
- an array containing the 3 HSL valuesalpha
- the alpha value between 0 - 1- Returns:
- the RGB Color object
-
toRGB
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.- Returns:
- the RGB Color object
-
toRGB
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- Returns:
- the RGB Color object
-