Class: HSVColor


CloudControl Pro 9 Docs / color / HSVColor

Class: HSVColor

color.HSVColor

A color represented using [alpha], [hue], [saturation], and [value]. An [HSVColor] is represented in a parameter space that's based on human perception of color in pigments (e.g. paint and printer's ink). The representation is useful for some color computations (e.g. rotating the hue through the colors), because interpolation and picking of colors as red, green, and blue channels doesn't always produce intuitive results. The HSV color space models the way that different pigments are perceived when mixed. The hue describes which pigment is used, the saturation describes which shade of the pigment, and the value resembles mixing the pigment with different amounts of black or white pigment. See also:

  • [HSLColor], a color that uses a color space based on human perception of colored light.
  • 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 pigment will be added to a color.


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 equivalent of how much of a pigment is added.


value

Readonly value: number

Value, from 0.0 to 1.0. The "value" of a color that, in this context, describes how bright a color is. A value of 0.0 indicates black, and 1.0 indicates full intensity color. You can think of this as the equivalent of removing black from the color as value increases.

Methods

_scaleAlpha

_scaleAlpha(factor): HSVColor

Parameters

Name Type
factor number

Returns

HSVColor


equals

equals(other): boolean

Parameters

Name Type
other any

Returns

boolean


toColor

toColor(): Color

Returns this color in RGB.

Returns

Color


toString

toString(): string

Returns

string


withAlpha

withAlpha(alpha): HSVColor

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

Parameters

Name Type
alpha number

Returns

HSVColor


withHue

withHue(hue): HSVColor

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

Parameters

Name Type
hue number

Returns

HSVColor


withSaturation

withSaturation(saturation): HSVColor

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

Parameters

Name Type
saturation number

Returns

HSVColor


withValue

withValue(value): HSVColor

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

Parameters

Name Type
value number

Returns

HSVColor


fromAHSV

Static fromAHSV(alpha, hue, saturation, value): HSVColor

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
value number

Returns

HSVColor


fromColor

Static fromColor(color): HSVColor

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

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

Parameters

Name Type
color Color

Returns

HSVColor


lerp

Static lerp(a, b, t): undefined | HSVColor

Linearly interpolate between two HSVColors.

The colors are interpolated by interpolating the [alpha], [hue], [saturation], and [value] 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.

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

Parameters

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

Returns

undefined | HSVColor