Class Color::HSL
In: lib/color/hsl.rb
Parent: Object

An HSL colour object. Internally, the hue (h), saturation (s), and luminosity/lightness (l) values are dealt with as fractional values in the range 0..1.

Methods

==   brightness   css_hsl   css_hsla   css_rgb   css_rgba   from_fraction   h   h=   html   hue   hue=   inspect   l   l=   lightness   lightness=   luminosity   luminosity=   mix_with   new   s   s=   saturation   saturation=   to_cmyk   to_grayscale   to_greyscale   to_hsl   to_rgb   to_yiq  

Public Class methods

Creates an HSL colour object from fractional values 0..1.

Creates an HSL colour object from the standard values of degrees and percentages (e.g., 145 deg, 30%, 50%).

Public Instance methods

Compares the other colour to this one. The other colour will be converted to HSL before comparison, so the comparison between a HSL colour and a non-HSL colour will be approximate and based on the other colour‘s to_hsl conversion. If there is no to_hsl conversion, this will raise an exception. This will report that two HSL values are equivalent if all component values are within Color::COLOR_TOLERANCE of each other.

Returns the luminosity (l) of the colour.

Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180, 25%, 35%)").

Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g., "hsla(180, 25%, 35%, 1)").

Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%, 100%)"). Note that this will perform a to_rgb operation using the default conversion formula.

Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g., "rgb(0%, 50%, 100%, 1)"). Note that this will perform a to_rgb operation using the default conversion formula.

Returns the hue of the colour in the range 0.0 .. 1.0.

Sets the hue of the colour in the range 0.0 .. 1.0.

Present the colour as an HTML/CSS colour string.

Returns the hue of the colour in degrees.

Sets the hue of the colour in degrees. Colour is perceived as a wheel, so values should be set properly even with negative degree values.

Returns the luminosity of the colour in the range 0.0 .. 1.0.

Sets the luminosity of the colour in the ragne 0.0 .. 1.0.

lightness()

Alias for luminosity

lightness=(ll)

Alias for luminosity=

Returns the percentage of luminosity of the colour.

Sets the percentage of luminosity of the colour.

Mix the mask colour (which will be converted to an HSL colour) with the current colour at the stated mix percentage as a decimal value.

NOTE:This differs from Color::RGB#mix_with.

Returns the saturation of the colour in the range 0.0 .. 1.0.

Sets the saturation of the colour in the ragne 0.0 .. 1.0.

Returns the percentage of saturation of the colour.

Sets the percentage of saturation of the colour.

Converts to RGB then CMYK.

to_grayscale()

Alias for to_greyscale

Converting to HSL as adapted from Foley and Van-Dam from www.bobpowell.net/RGBHSB.htm.

NOTE:

  • If the colour‘s luminosity is near zero, the colour is always black.
  • If the colour‘s luminosity is near one, the colour is always white.
  • If the colour‘s saturation is near zero, the colour is always a shade of grey and is based only on the luminosity of the colour.

Converts to RGB then YIQ.

[Validate]