dreamworkAPI
Ctrl K
GitHub
libraryDocs / color

color

librarysharedmenusource

Library for color manipulation.

Classes & types

Functions

color.addAdds two colors.
color.divDivides two colors.
color.fromCMYKCreates a color from CMYK values.
color.fromHexConverts a hexadecimal color string to color.
color.fromHSLCreates a color from HSL values (hue, saturation, lightness).
color.fromHSVCreates a color from HSV values.
color.fromHWBCreates a color from HWB values.
color.fromRGBConverts RGBA components to a color value.
color.fromStringParses a color from a binary string.
color.getBlacknessReturns the color's blackness.
color.getBrightnessReturns the color's brightness.
color.getHueReturns the color's hue.
color.getLightnessReturns the color's lightness.
color.getLuminanceReturns the color's luminance.
color.getSaturationReturns the color's saturation.
color.getWhitenessReturns the color's whiteness.
color.invertInverts a color value.
color.lerpSmoothing two colors by fraction.
color.mulMultiplies two colors.
color.setBlacknessSets the color's blackness.
color.setBrightnessSets the color's brightness.
color.setHueSets the color's hue.
color.setLightnessSets the color's lightness.
color.setSaturationSets the color's saturation.
color.setWhitenessSets the color's whiteness.
color.subSubtracts two colors.
color.toCMYKReturns the color as CMYK values (cyan, magenta, yellow, black).
color.toHexConverts a color value to a hexadecimal string.
color.toHSLConverts a color to HSL values (hue, saturation, lightness).
color.toHSVReturns the color as HSV values (hue, saturation, value).
color.toHWBReturns the color as HWB values (hue, whiteness, blackness).
color.toRGBConverts a color value to RGBA components.
color.toStringReturns the color as binary string.

#color.add

sharedmenusource
function color.add(value1: Color, value2: Color)

Adds two colors.

Parameters
NameTypeDescription
value1ColorThe first color to add.
value2ColorThe second color to add.

#color.div

sharedmenunodiscardsource
function color.div(value1: Color, value2: Color): Color

Divides two colors.

Parameters
NameTypeDescription
value1ColorThe first color to divide.
value2ColorThe second color to divide.
Returns
TypeNameDescription
Colornew_colorThe result of the division.

#color.fromCMYK

sharedmenunodiscardsource
function color.fromCMYK(cyan: number, magenta: number, yellow: number, black: number): Color

Creates a color from CMYK values.

Parameters
NameTypeDescription
cyannumberThe cyan as fraction [0, 1].
magentanumberThe magenta as fraction [0, 1].
yellownumberThe yellow as fraction [0, 1].
blacknumberThe black as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.fromHex

sharedmenunodiscardsource
function color.fromHex(hex_str: string): Color

Converts a hexadecimal color string to color.

Formats:

0xRRGGBB / #RRGGBB / RRGGBB

Parameters
NameTypeDescription
hex_strstringThe hexadecimal color string to convert.
Returns
TypeNameDescription
ColorcolorThe color value.

#color.fromHSL

sharedmenunodiscardsource
function color.fromHSL(hue: integer, saturation: number, lightness: number): Color

Creates a color from HSL values (hue, saturation, lightness).

Parameters
NameTypeDescription
hueintegerThe hue in degrees [0, 360].
saturationnumberThe saturation [0, 1].
lightnessnumberThe lightness [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.fromHSV

sharedmenunodiscardsource
function color.fromHSV(hue: integer, saturation: number, brightness: number): Color

Creates a color from HSV values.

Parameters
NameTypeDescription
hueintegerThe hue in degrees [0, 360].
saturationnumberThe saturation [0, 1].
brightnessnumberThe brightness [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.fromHWB

sharedmenunodiscardsource
function color.fromHWB(hue: integer, saturation: number, brightness: number): Color

Creates a color from HWB values.

Parameters
NameTypeDescription
hueintegerThe hue in degrees [0, 360].
saturationnumberThe saturation [0, 1].
brightnessnumberThe brightness [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.fromRGB

sharedmenunodiscardsource
function color.fromRGB(red: integer, green: integer, blue: integer): Color

Converts RGBA components to a color value.

Parameters
NameTypeDescription
redintegerThe 8-bit red channel, in the range [0, 255].
greenintegerThe 8-bit green channel, in the range [0, 255].
blueintegerThe 8-bit blue channel, in the range [0, 255].
Returns
TypeNameDescription
ColorcolorThe color value.

#color.fromString

sharedmenunodiscardsource
function color.fromString(str: string, start_position?: integer, str_length?: integer): Color

Parses a color from a binary string.

Parameters
NameTypeDescription
strstringThe binary string to parse.
start_positionoptionalintegerThe starting position in the string.
str_lengthoptionalintegerThe length of the string to parse.
Returns
TypeNameDescription
Colornew_colorThe parsed color.

#color.getBlackness

sharedmenunodiscardsource
function color.getBlackness(color: Color): number

Returns the color's blackness.

Parameters
NameTypeDescription
colorColorThe color to get the blackness of.
Returns
TypeNameDescription
numberblacknessThe blackness as fraction [0, 1].

#color.getBrightness

sharedmenunodiscardsource
function color.getBrightness(color: Color): number

Returns the color's brightness.

Parameters
NameTypeDescription
colorColorThe color to get the brightness of.
Returns
TypeNameDescription
numberbrightnessThe brightness as fraction [0, 1].

#color.getHue

sharedmenunodiscardsource
function color.getHue(color: Color): integer

Returns the color's hue.

Parameters
NameTypeDescription
colorColorThe color to get the hue of.
Returns
TypeNameDescription
integerhueThe hue in degrees [0, 360].

#color.getLightness

sharedmenunodiscardsource
function color.getLightness(color: Color): number

Returns the color's lightness.

Parameters
NameTypeDescription
colorColorThe color to get the lightness of.
Returns
TypeNameDescription
numberlightnessThe lightness as fraction [0, 1].

#color.getLuminance

sharedmenunodiscardsource
function color.getLuminance(color: Color): number

Returns the color's luminance.

Parameters
NameTypeDescription
colorColorThe color to get the luminance of.
Returns
TypeNameDescription
numberluminanceThe luminance as integer [0, 255].

#color.getSaturation

sharedmenunodiscardsource
function color.getSaturation(color: Color): number

Returns the color's saturation.

Parameters
NameTypeDescription
colorColorThe color to get the saturation of.
Returns
TypeNameDescription
numbersaturationThe saturation as fraction [0, 1].

#color.getWhiteness

sharedmenunodiscardsource
function color.getWhiteness(color: Color): number

Returns the color's whiteness.

Parameters
NameTypeDescription
colorColorThe color to get the whiteness of.
Returns
TypeNameDescription
numberwhitenessThe whiteness as fraction [0, 1].

#color.invert

sharedmenunodiscardsource
function color.invert(color: Color): Color

Inverts a color value.

Parameters
NameTypeDescription
colorColorThe color value to invert.
Returns
TypeNameDescription
ColorThe inverted color value.

#color.lerp

sharedmenunodiscardsource
function color.lerp(frac: number, color: Color, color2: Color): Color

Smoothing two colors by fraction.

Parameters
NameTypeDescription
fracnumberThe interpolation factor.
colorColorThe starting color.
color2ColorThe ending color.
Returns
TypeNameDescription
ColorThe interpolated color.

#color.mul

sharedmenunodiscardsource
function color.mul(value1: Color, value2: Color): Color

Multiplies two colors.

Parameters
NameTypeDescription
value1ColorThe first color to multiply.
value2ColorThe second color to multiply.
Returns
TypeNameDescription
Colornew_colorThe result of the multiplication.

#color.setBlackness

sharedmenunodiscardsource
function color.setBlackness(color: Color, blackness: number): Color

Sets the color's blackness.

Parameters
NameTypeDescription
colorColorThe color to set the blackness of.
blacknessnumberThe blackness as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.setBrightness

sharedmenunodiscardsource
function color.setBrightness(color: Color, brightness: number): Color

Sets the color's brightness.

Parameters
NameTypeDescription
colorColorThe color to set the brightness of.
brightnessnumberThe brightness as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.setHue

sharedmenunodiscardsource
function color.setHue(color: Color, hue: integer): Color

Sets the color's hue.

Parameters
NameTypeDescription
colorColorThe color to set the hue of.
hueintegerThe hue in degrees [0, 360].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.setLightness

sharedmenunodiscardsource
function color.setLightness(color: Color, lightness: number): Color

Sets the color's lightness.

Parameters
NameTypeDescription
colorColorThe color to set the lightness of.
lightnessnumberThe lightness as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.setSaturation

sharedmenunodiscardsource
function color.setSaturation(color: Color, saturation: number): Color

Sets the color's saturation.

Parameters
NameTypeDescription
colorColorThe color to set the saturation of.
saturationnumberThe saturation as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.setWhiteness

sharedmenunodiscardsource
function color.setWhiteness(color: Color, whiteness: number): Color

Sets the color's whiteness.

Parameters
NameTypeDescription
colorColorThe color to set the whiteness of.
whitenessnumberThe whiteness as fraction [0, 1].
Returns
TypeNameDescription
Colornew_colorThe new color.

#color.sub

sharedmenunodiscardsource
function color.sub(value1: Color, value2: Color): Color

Subtracts two colors.

Parameters
NameTypeDescription
value1ColorThe first color to subtract.
value2ColorThe second color to subtract.
Returns
TypeNameDescription
Colornew_colorThe result of the subtraction.

#color.toCMYK

sharedmenunodiscardsource
function color.toCMYK(color: Color): number, number, number, number

Returns the color as CMYK values (cyan, magenta, yellow, black).

Parameters
NameTypeDescription
colorColorThe color to convert to CMYK.
Returns
TypeNameDescription
numbercyanThe cyan as fraction [0, 1].
numbermagentaThe magenta as fraction [0, 1].
numberyellowThe yellow as fraction [0, 1].
numberblackThe black as fraction [0, 1].

#color.toHex

sharedmenunodiscardsource
function color.toHex(color: Color): string

Converts a color value to a hexadecimal string.

Parameters
NameTypeDescription
colorColorThe color to convert.
Returns
TypeNameDescription
stringThe hexadecimal representation of the color.

#color.toHSL

sharedmenunodiscardsource
function color.toHSL(color: Color): integer, number, number

Converts a color to HSL values (hue, saturation, lightness).

Parameters
NameTypeDescription
colorColorThe color to convert.
Returns
TypeNameDescription
integerhueThe hue in degrees [0, 360].
numbersaturationThe saturation as fraction [0, 1].
numberlightnessThe lightness as fraction [0, 1].

#color.toHSV

sharedmenunodiscardsource
function color.toHSV(color: Color): integer, number, number

Returns the color as HSV values (hue, saturation, value).

Parameters
NameTypeDescription
colorColorThe color to convert.
Returns
TypeNameDescription
integerhueThe hue in degrees [0, 360].
numbersaturationThe saturation as fraction [0, 1].
numbervalueThe value as fraction [0, 1].

#color.toHWB

sharedmenunodiscardsource
function color.toHWB(color: Color): integer, number, number

Returns the color as HWB values (hue, whiteness, blackness).

Parameters
NameTypeDescription
colorColorThe color to convert to HWB.
Returns
TypeNameDescription
integerhueThe hue in degrees [0, 360].
numberwhitenessThe whiteness as fraction [0, 1].
numberblacknessThe blackness as fraction [0, 1].

#color.toRGB

sharedmenunodiscardsource
function color.toRGB(color: Color): integer, integer, integer

Converts a color value to RGBA components.

Parameters
NameTypeDescription
colorColorThe color value to convert.
Returns
TypeNameDescription
integerredThe 8-bit red channel, in the range [0, 255].
integergreenThe 8-bit green channel, in the range [0, 255].
integerblueThe 8-bit blue channel, in the range [0, 255].

#color.toString

sharedmenunodiscardsource
function color.toString(color: Color): string

Returns the color as binary string.

Parameters
NameTypeDescription
colorColorThe color to convert.
Returns
TypeNameDescription
stringbinary_stringThe color as binary string.
Generated from the dreamwork meta branch.