Skip to main content

Class: ColorUtils

Defined in: src/sdk/graphics/color/ColorUtils.ts:6

A utility class for working with colors.

Constructors​

Constructor​

new ColorUtils(): ColorUtils

Returns​

ColorUtils

Methods​

gradientHex()​

static gradientHex<T>(color1, color2): (fraction) => T

Defined in: src/sdk/graphics/color/ColorUtils.ts:469

Creates a function that linearly interpolates between two colors in the RGB colorspace.

Type Parameters​

Type ParameterDefault type
Tstring | number

Parameters​

ParameterTypeDescription
color1TThe first color to interpolate between.
color2TThe second color to interpolate between.

Returns​

A function that linearly interpolates between the two specified colors in the RGB colorspace.

(fraction): T

Parameters​
ParameterType
fractionnumber
Returns​

T


hexNumberToString()​

static hexNumberToString(hex, reverse): string

Defined in: src/sdk/graphics/color/ColorUtils.ts:65

Converts a numeric representation of a hex color to a string.

Parameters​

ParameterTypeDefault valueDescription
hexnumberundefinedThe numeric hex color to convert. The color will be interpreted as an integer with the value (red << 16) + (green << 8) + (blue << 0). Bits with value greater than or equal to 1 << 24 will be discarded.
reversebooleanfalseWhether to interpret the numeric hex color with reversed components. If true, then the numeric hex color will be interpreted as (blue << 16) + (green << 8) + (red << 0). Defaults to false.

Returns​

string

The string form of the specified numeric hex color.


hexStringToNumber()​

static hexStringToNumber(hex, reverse): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:39

Converts a hex color string to its numeric representation. The numeric hex color is equal to (red << 16) + (green << 8) + (blue << 0).

Parameters​

ParameterTypeDefault valueDescription
hexstringundefinedThe hex color string to convert. The string should be a sequence of exactly six hexadecimal characters optionally prefixed with #.
reversebooleanfalseWhether to reverse the order in which the red, green, and blue components are concatenated in the numeric representation. If true, then the numeric hex color will equal (blue << 16) + (green << 8) + (red << 0). Defaults to false.

Returns​

number

The numeric representation of the specified hex color string.

Throws​

Error if the string is improperly formatted.


hexToHsl()​

static hexToHsl<T>(hex, out, reverse): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:318

Converts a hex color to hue, saturation, and lightness (HSL) components. Hue is expressed in degrees (0 to 360), and saturation and lightness are expressed as fractions (0 to 1).

Type Parameters​

Type Parameter
T extends Float64Array | number[]

Parameters​

ParameterTypeDefault valueDescription
hexstring | numberundefinedThe hex color to convert, either as a string containing a sequence of exactly six hexadecimal characters optionally prefixed with # or a numeric value equal to (red << 16) + (green << 8) + (blue << 0) (bits with value greater than or equal to 1 << 24 will be discarded).
outTundefinedThe array to which to write the results.
reversebooleanfalseWhether to interpret the numeric hex color with reversed components. If true, then the numeric hex color will be interpreted as (blue << 16) + (green << 8) + (red << 0). Ignored if hex is a string. Defaults to false.

Returns​

T

The hue, saturation, and lightness (HSL) color components of the specified hex color, as [h, s, l].

Throws​

Error if the specified hex color is an improperly formatted string.


hexToRgb()​

static hexToRgb<T>(hex, out, reverse): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:85

Converts a hex color to red, green, and blue (RGB) components. Each component is expressed in the range 0 to 255.

Type Parameters​

Type Parameter
T extends Float64Array | number[]

Parameters​

ParameterTypeDefault valueDescription
hexstring | numberundefinedThe hex color to convert, either as a string containing a sequence of exactly six hexadecimal characters optionally prefixed with # or a numeric value equal to (red << 16) + (green << 8) + (blue << 0) (bits with value greater than or equal to 1 << 24 will be discarded).
outTundefinedThe array to which to write the results.
reversebooleanfalseWhether to interpret the numeric hex color with reversed components. If true, then the numeric hex color will be interpreted as (blue << 16) + (green << 8) + (red << 0). Ignored if hex is a string. Defaults to false.

Returns​

T

The red, green, and blue (RGB) components of the specified hex color, as [r, g, b].

Throws​

Error if the specified hex color is an improperly formatted string.


hslToHex()​

Call Signature​

static hslToHex(hsl, reverse?): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:334

Converts hue, saturation, and lightness (HSL) color components to a numeric hex color. The numeric hex color is equal to (red << 16) + (green << 8) + (blue << 0).

Parameters​
ParameterTypeDescription
hslFloat64Array | number[]The HSL color to convert, as [h, s, l]. Hue should be expressed in degrees, and saturation and lightness should be expressed as fractions in the range 0 to 1.
reverse?booleanWhether to reverse the order in which the red, green, and blue components are concatenated in the numeric representation. If true, then the numeric hex color will equal (blue << 16) + (green << 8) + (red << 0). Defaults to false.
Returns​

number

The numeric hex color representation of the specified HSL color.

Call Signature​

static hslToHex(h, s, l, reverse?): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:346

Converts hue, saturation, and lightness (HSL) color components to a numeric hex color. The numeric hex color is equal to (red << 16) + (green << 8) + (blue << 0).

Parameters​
ParameterTypeDescription
hnumberThe hue component of the color to convert, in degrees.
snumberThe saturation component of the color to convert, as a fraction in the range 0 to 1.
lnumberThe lightness component of the color to convert, as a fraction in the range 0 to 1.
reverse?booleanWhether to reverse the order in which the red, green, and blue components are concatenated in the numeric representation. If true, then the numeric hex color will equal (blue << 16) + (green << 8) + (red << 0). Defaults to false.
Returns​

number

The numeric hex color representation of the specified HSL color.


hslToRgb()​

Call Signature​

static hslToRgb<T>(hsl, out): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:230

Converts hue, saturation, and lightness (HSL) color components to red, green, and blue (RGB) components. Each RGB component is expressed in the range 0 to 255.

Type Parameters​
Type Parameter
T extends Float64Array | number[]
Parameters​
ParameterTypeDescription
hslFloat64Array | number[]The HSL color to convert, as [h, s, l]. Hue should be expressed in degrees, and saturation and lightness should be expressed as fractions in the range 0 to 1.
outTThe array to which to write the results.
Returns​

T

The red, green, and blue (RGB) color components of the specified HSL color, as [r, g, b].

Call Signature​

static hslToRgb<T>(h, s, l, out): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:240

Converts hue, saturation, and lightness (HSL) color components to red, green, and blue (RGB) components. Each RGB component is expressed in the range 0 to 255.

Type Parameters​
Type Parameter
T extends Float64Array | number[]
Parameters​
ParameterTypeDescription
hnumberThe hue component of the color to convert, in degrees.
snumberThe saturation component of the color to convert, as a fraction in the range 0 to 1.
lnumberThe lightness component of the color to convert, as a fraction in the range 0 to 1.
outTThe array to which to write the results.
Returns​

T

The red, green, and blue (RGB) color components of the specified HSL color, as [r, g, b].


interpolateHex()​

Call Signature​

static interpolateHex<T>(color1, color2, fraction): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:370

Linearly interpolates between two hex colors in the RGB colorspace.

Type Parameters​
Type ParameterDefault type
Tstring | number
Parameters​
ParameterTypeDescription
color1TThe first color to interpolate between.
color2TThe second color to interpolate between.
fractionnumberThe position between the two colors at which to generate the interpolated color, as a number in the range [0, 1]. A value of 0 is equivalent to the first color, and a value of 1 is equivalent to the second color.
Returns​

T

The color that is the result of interpolating between the two specified colors at the specified position.

Call Signature​

static interpolateHex<T>(color1, color2, fraction, out?): T[]

Defined in: src/sdk/graphics/color/ColorUtils.ts:383

Linearly interpolates between two hex colors in the RGB colorspace.

Type Parameters​
Type ParameterDefault type
Tstring | number
Parameters​
ParameterTypeDescription
color1TThe first color to interpolate between.
color2TThe second color to interpolate between.
fractionreadonly number[]An array of positions between the two colors at which to generate interpolated colors. Each position is a number in the range [0, 1]. A value of 0 is equivalent to the first color, and a value of 1 is equivalent to the second color.
out?T[]The array to which to write the interpolated colors.
Returns​

T[]

An array of colors that are the result of interpolating between the two specified colors at the positions specified by fraction. The index of each color in the array matches the index of the position used to generate it in fraction.


reverseHexNumber()​

static reverseHexNumber(hex): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:24

Reverses the order of concatenation of the red, green, and blue components in a numeric hex color. A value equal to (red << 16) + (green << 8) + (blue << 0) will be converted to (blue << 16) + (green << 8) + (red << 0) and vice versa.

Parameters​

ParameterTypeDescription
hexnumberThe numeric hex color to reverse.

Returns​

number

The specified numeric hex color with the concatenation order of red, green, and blue components reversed.


rgbToHex()​

Call Signature​

static rgbToHex(rgb, reverse?): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:114

Converts red, green, and blue (RGB) color components to a numeric hex color. The numeric hex color is equal to (red << 16) + (green << 8) + (blue << 0).

Parameters​
ParameterTypeDescription
rgbFloat64Array | number[]The RGB color to convert, as [r, g, b]. Each component should be in the range 0 to 255.
reverse?booleanWhether to reverse the order in which the red, green, and blue components are concatenated in the numeric representation. If true, then the numeric hex color will equal (blue << 16) + (green << 8) + (red << 0). Defaults to false.
Returns​

number

The numeric hex color representation of the specified RGB color.

Call Signature​

static rgbToHex(r, g, b, reverse?): number

Defined in: src/sdk/graphics/color/ColorUtils.ts:126

Converts red, green, and blue (RGB) color components to a numeric hex color. The numeric hex color is equal to (red << 16) + (green << 8) + (blue << 0).

Parameters​
ParameterTypeDescription
rnumberThe red component of the color to convert, in the range 0 to 255.
gnumberThe green component of the color to convert, in the range 0 to 255.
bnumberThe blue component of the color to convert, in the range 0 to 255.
reverse?booleanWhether to reverse the order in which the red, green, and blue components are concatenated in the numeric representation. If true, then the numeric hex color will equal (blue << 16) + (green << 8) + (red << 0). Defaults to false.
Returns​

number

The numeric hex color representation of the specified RGB color.


rgbToHsl()​

Call Signature​

static rgbToHsl<T>(rgb, out): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:165

Converts red, green, and blue (RGB) color components to hue, saturation, and lightness (HSL) components. Hue is expressed in degrees (0 to 360), and saturation and lightness are expressed as fractions (0 to 1).

Type Parameters​
Type Parameter
T extends Float64Array | number[]
Parameters​
ParameterTypeDescription
rgbFloat64Array | number[]The RGB color to convert, as [r, g, b]. Each component should be in the range 0 to 255.
outTThe array to which to write the results.
Returns​

T

The hue, saturation, and lightness (HSL) color components of the specified RGB color, as [h, s, l].

Call Signature​

static rgbToHsl<T>(r, g, b, out): T

Defined in: src/sdk/graphics/color/ColorUtils.ts:175

Converts red, green, and blue (RGB) color components to hue, saturation, and lightness (HSL) components. Hue is expressed in degrees (0 to 360), and saturation and lightness are expressed as fractions (0 to 1).

Type Parameters​
Type Parameter
T extends Float64Array | number[]
Parameters​
ParameterTypeDescription
rnumberThe red component of the color to convert, in the range 0 to 255.
gnumberThe green component of the color to convert, in the range 0 to 255.
bnumberThe blue component of the color to convert, in the range 0 to 255.
outTThe array to which to write the results.
Returns​

T

The hue, saturation, and lightness (HSL) color components of the specified RGB color, as [h, s, l].