类: HSLColor


类: 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.

目录

属性

方法

属性

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.

方法

_scaleAlpha

_scaleAlpha(factor): HSLColor

参数

名称 类型
factor number

返回值

HSLColor


equals

equals(other): boolean

参数

名称 类型
other any

返回值

boolean


toColor

toColor(): Color

Returns this HSL color in RGB.

返回值

Color


toString

toString(): String

返回值

String


withAlpha

withAlpha(alpha): HSLColor

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

参数

名称 类型
alpha number

返回值

HSLColor


withHue

withHue(hue): HSLColor

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

参数

名称 类型
hue number

返回值

HSLColor


withLightness

withLightness(lightness): HSLColor

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

参数

名称 类型
lightness number

返回值

HSLColor


withSaturation

withSaturation(saturation): HSLColor

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

参数

名称 类型
saturation number

返回值

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.

参数

名称 类型
alpha number
hue number
saturation number
lightness number

返回值

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.

参数

名称 类型
color Color

返回值

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].

参数

名称 类型
a null | HSLColor
b null | HSLColor
t number

返回值

null | HSLColor