Class: HSLColor


CloudControl Pro 9 Docs / color / HSLColor

Class: HSLColor

color.HSLColor

A color represented using [alpha], [hue], [saturation], and [lightness].

An [HSLColor] is represented in a parameter space that's based up human perception of colored light. The representation is useful for some color computations (e.g., combining colors of light), because interpolation and picking of colors as red, green, and blue channels doesn't always produce intuitive results.

HSL is a perceptual color model, placing fully saturated colors around a circle (conceptually) at a lightness of ​0.5, with a lightness of 0.0 being completely black, and a lightness of 1.0 being completely white. As the lightness increases or decreases from 0.5, the apparent saturation decreases proportionally (even though the [saturation] parameter hasn't changed).

See also:

  • [HSVColor], a color that uses a color space based on human perception of pigments (e.g. paint and printer's ink).
  • HSV and HSLopen in new window Wikipedia article, which this implementation is based upon.

Table of contents

Properties

Methods

Properties

alpha

Readonly alpha: number

Alpha, from 0.0 to 1.0. The describes the transparency of the color. A value of 0.0 is fully transparent, and 1.0 is fully opaque.


hue

Readonly hue: number

Hue, from 0.0 to 360.0. Describes which color of the spectrum is represented. A value of 0.0 represents red, as does 360.0. Values in between go through all the hues representable in RGB. You can think of this as selecting which color filter is placed over a light.


lightness

Readonly lightness: number

Lightness, from 0.0 to 1.0. The lightness of a color describes how bright a color is. A value of 0.0 indicates black, and 1.0 indicates white. You can think of this as the intensity of the light behind the filter. As the lightness approaches 0.5, the colors get brighter and appear more saturated, and over 0.5, the colors start to become less saturated and approach white at 1.0.


saturation

Readonly saturation: number

Saturation, from 0.0 to 1.0. This describes how colorful the color is. 0.0 implies a shade of grey (i.e. no pigment), and 1.0 implies a color as vibrant as that hue gets. You can think of this as the purity of the color filter over the light.

Methods

_scaleAlpha

_scaleAlpha(factor): HSLColor

Parameters

Name Type
factor number

Returns

HSLColor


equals

equals(other): boolean

Parameters

Name Type
other any

Returns

boolean


toColor

toColor(): Color

Returns this HSL color in RGB.

Returns

Color


toString

toString(): String

Returns

String


withAlpha

withAlpha(alpha): HSLColor

Returns a copy of this color with the alpha parameter replaced with the given value.

Parameters

Name Type
alpha number

Returns

HSLColor


withHue

withHue(hue): HSLColor

Returns a copy of this color with the [hue] parameter replaced with the given value.

Parameters

Name Type
hue number

Returns

HSLColor


withLightness

withLightness(lightness): HSLColor

Returns a copy of this color with the [lightness] parameter replaced with the given value.

Parameters

Name Type
lightness number

Returns

HSLColor


withSaturation

withSaturation(saturation): HSLColor

Returns a copy of this color with the [saturation] parameter replaced with the given value.

Parameters

Name Type
saturation number

Returns

HSLColor


fromAHSL

Static fromAHSL(alpha, hue, saturation, lightness): HSLColor

Creates a color.

All the arguments must not be null and be in their respective ranges. See the fields for each parameter for a description of their ranges.

Parameters

Name Type
alpha number
hue number
saturation number
lightness number

Returns

HSLColor


fromColor

Static fromColor(color): HSLColor

Creates an [HSLColor] from an RGB [Color].

This constructor does not necessarily round-trip with [toColor] because of floating point imprecision.

Parameters

Name Type
color Color

Returns

HSLColor


lerp

Static lerp(a, b, t): null | HSLColor

Linearly interpolate between two HSLColors.

The colors are interpolated by interpolating the [alpha], [hue], [saturation], and [lightness] channels separately, which usually leads to a more pleasing effect than [Color.lerp] (which interpolates the red, green, and blue channels separately).

If either color is null, this function linearly interpolates from a transparent instance of the other color. This is usually preferable to interpolating from [Colors.transparent] (const Color(0x00000000)) since that will interpolate from a transparent red and cycle through the hues to match the target color, regardless of what that color's hue is.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values between them meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as [Curves.elasticInOut]).

Values outside of the valid range for each channel will be clamped.

Values for t are usually obtained from an [Animation<double>], such as an [AnimationController].

Parameters

Name Type
a null | HSLColor
b null | HSLColor
t number

Returns

null | HSLColor