Skip to main content

Class: ColorUtils

A utility class for working with colors.

Constructors

constructor

new ColorUtils(): ColorUtils

Returns

ColorUtils

Methods

gradientHex

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

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

Type parameters

NameType
Tstring | number

Parameters

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

Returns

fn

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

▸ (fraction): T

Parameters
NameType
fractionnumber
Returns

T

Defined in

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


hexNumberToString

hexNumberToString(hex, reverse?): string

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

Parameters

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

Defined in

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


hexStringToNumber

hexStringToNumber(hex, reverse?): number

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

Parameters

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

Defined in

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


hexToHsl

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

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

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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


hexToRgb

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

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

Type parameters

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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


hslToHex

hslToHex(hsl, reverse?): number

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

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

Defined in

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

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

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

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

Defined in

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


hslToRgb

hslToRgb<T>(hsl, out): T

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

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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

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

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

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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


interpolateHex

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

Linearly interpolates between two hex colors in the RGB colorspace.

Type parameters

NameType
Tstring | number

Parameters

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

Defined in

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

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

Linearly interpolates between two hex colors in the RGB colorspace.

Type parameters

NameType
Tstring | number

Parameters

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

Defined in

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


reverseHexNumber

reverseHexNumber(hex): number

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

NameTypeDescription
hexnumberThe numeric hex color to reverse.

Returns

number

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

Defined in

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


rgbToHex

rgbToHex(rgb, reverse?): number

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

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

Defined in

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

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

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

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

Defined in

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


rgbToHsl

rgbToHsl<T>(rgb, out): T

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

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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

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

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

NameType
Textends Float64Array | number[]

Parameters

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

Defined in

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