Class: Color::HSL

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

from_fraction(h = 0.0, s = 0.0, l = 0.0)

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

new(h = 0, s = 0, l = 0)

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

### Public Instance methods

==(other)

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.

brightness()

Returns the luminosity (l) of the colour.

css_hsl()

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

css_hsla()

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

css_rgb()

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.

css_rgba()

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.

h()

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

h=(hh)

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

html()

Present the colour as an HTML/CSS colour string.

hue()

Returns the hue of the colour in degrees.

hue=(hh)

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.

inspect()
l()

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

l=(ll)

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

lightness()

Alias for luminosity

lightness=(ll)

Alias for luminosity=

luminosity()

Returns the percentage of luminosity of the colour.

luminosity=(ll)

Sets the percentage of luminosity of the colour.

mix_with(color, mix_percent = 0.5)

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.

s()

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

s=(ss)

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

saturation()

Returns the percentage of saturation of the colour.

saturation=(ss)

Sets the percentage of saturation of the colour.

to_cmyk()

Converts to RGB then CMYK.

to_grayscale()

Alias for to_greyscale

to_greyscale()
to_hsl()
to_rgb(ignored = nil)

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.

to_yiq()

Converts to RGB then YIQ.

[Validate]