color
Library for color manipulation.
Classes & types
Functions
color.add | Adds two colors. |
color.div | Divides two colors. |
color.fromCMYK | Creates a color from CMYK values. |
color.fromHex | Converts a hexadecimal color string to color. |
color.fromHSL | Creates a color from HSL values (hue, saturation, lightness). |
color.fromHSV | Creates a color from HSV values. |
color.fromHWB | Creates a color from HWB values. |
color.fromRGB | Converts RGBA components to a color value. |
color.fromString | Parses a color from a binary string. |
color.getBlackness | Returns the color's blackness. |
color.getBrightness | Returns the color's brightness. |
color.getHue | Returns the color's hue. |
color.getLightness | Returns the color's lightness. |
color.getLuminance | Returns the color's luminance. |
color.getSaturation | Returns the color's saturation. |
color.getWhiteness | Returns the color's whiteness. |
color.invert | Inverts a color value. |
color.lerp | Smoothing two colors by fraction. |
color.mul | Multiplies two colors. |
color.setBlackness | Sets the color's blackness. |
color.setBrightness | Sets the color's brightness. |
color.setHue | Sets the color's hue. |
color.setLightness | Sets the color's lightness. |
color.setSaturation | Sets the color's saturation. |
color.setWhiteness | Sets the color's whiteness. |
color.sub | Subtracts two colors. |
color.toCMYK | Returns the color as CMYK values (cyan, magenta, yellow, black). |
color.toHex | Converts a color value to a hexadecimal string. |
color.toHSL | Converts a color to HSL values (hue, saturation, lightness). |
color.toHSV | Returns the color as HSV values (hue, saturation, value). |
color.toHWB | Returns the color as HWB values (hue, whiteness, blackness). |
color.toRGB | Converts a color value to RGBA components. |
color.toString | Returns the color as binary string. |
function color.add(value1: Color, value2: Color)
Parameters
| Name | Type | Description |
|---|
value1 | Color | The first color to add. |
value2 | Color | The second color to add. |
function color.div(value1: Color, value2: Color): Color
Parameters
| Name | Type | Description |
|---|
value1 | Color | The first color to divide. |
value2 | Color | The second color to divide. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The result of the division. |
function color.fromCMYK(cyan: number, magenta: number, yellow: number, black: number): Color
Creates a color from CMYK values.
Parameters
| Name | Type | Description |
|---|
cyan | number | The cyan as fraction [0, 1]. |
magenta | number | The magenta as fraction [0, 1]. |
yellow | number | The yellow as fraction [0, 1]. |
black | number | The black as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.fromHex(hex_str: string): Color
Converts a hexadecimal color string to color.
Formats:
0xRRGGBB / #RRGGBB / RRGGBB
Parameters
| Name | Type | Description |
|---|
hex_str | string | The hexadecimal color string to convert. |
Returns
| Type | Name | Description |
|---|
Color | color | The color value. |
function color.fromHSL(hue: integer, saturation: number, lightness: number): Color
Creates a color from HSL values (hue, saturation, lightness).
Parameters
| Name | Type | Description |
|---|
hue | integer | The hue in degrees [0, 360]. |
saturation | number | The saturation [0, 1]. |
lightness | number | The lightness [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.fromHSV(hue: integer, saturation: number, brightness: number): Color
Creates a color from HSV values.
Parameters
| Name | Type | Description |
|---|
hue | integer | The hue in degrees [0, 360]. |
saturation | number | The saturation [0, 1]. |
brightness | number | The brightness [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.fromHWB(hue: integer, saturation: number, brightness: number): Color
Creates a color from HWB values.
Parameters
| Name | Type | Description |
|---|
hue | integer | The hue in degrees [0, 360]. |
saturation | number | The saturation [0, 1]. |
brightness | number | The brightness [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.fromRGB(red: integer, green: integer, blue: integer): Color
Converts RGBA components to a color value.
Parameters
| Name | Type | Description |
|---|
red | integer | The 8-bit red channel, in the range [0, 255]. |
green | integer | The 8-bit green channel, in the range [0, 255]. |
blue | integer | The 8-bit blue channel, in the range [0, 255]. |
Returns
| Type | Name | Description |
|---|
Color | color | The color value. |
function color.fromString(str: string, start_position?: integer, str_length?: integer): Color
Parses a color from a binary string.
Parameters
| Name | Type | Description |
|---|
str | string | The binary string to parse. |
start_positionoptional | integer | The starting position in the string. |
str_lengthoptional | integer | The length of the string to parse. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The parsed color. |
function color.getBlackness(color: Color): number
Returns the color's blackness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the blackness of. |
Returns
| Type | Name | Description |
|---|
number | blackness | The blackness as fraction [0, 1]. |
function color.getBrightness(color: Color): number
Returns the color's brightness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the brightness of. |
Returns
| Type | Name | Description |
|---|
number | brightness | The brightness as fraction [0, 1]. |
function color.getHue(color: Color): integer
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the hue of. |
Returns
| Type | Name | Description |
|---|
integer | hue | The hue in degrees [0, 360]. |
function color.getLightness(color: Color): number
Returns the color's lightness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the lightness of. |
Returns
| Type | Name | Description |
|---|
number | lightness | The lightness as fraction [0, 1]. |
function color.getLuminance(color: Color): number
Returns the color's luminance.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the luminance of. |
Returns
| Type | Name | Description |
|---|
number | luminance | The luminance as integer [0, 255]. |
function color.getSaturation(color: Color): number
Returns the color's saturation.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the saturation of. |
Returns
| Type | Name | Description |
|---|
number | saturation | The saturation as fraction [0, 1]. |
function color.getWhiteness(color: Color): number
Returns the color's whiteness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to get the whiteness of. |
Returns
| Type | Name | Description |
|---|
number | whiteness | The whiteness as fraction [0, 1]. |
function color.invert(color: Color): Color
Parameters
| Name | Type | Description |
|---|
color | Color | The color value to invert. |
Returns
| Type | Name | Description |
|---|
Color | | The inverted color value. |
function color.lerp(frac: number, color: Color, color2: Color): Color
Smoothing two colors by fraction.
Parameters
| Name | Type | Description |
|---|
frac | number | The interpolation factor. |
color | Color | The starting color. |
color2 | Color | The ending color. |
Returns
| Type | Name | Description |
|---|
Color | | The interpolated color. |
function color.mul(value1: Color, value2: Color): Color
Parameters
| Name | Type | Description |
|---|
value1 | Color | The first color to multiply. |
value2 | Color | The second color to multiply. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The result of the multiplication. |
function color.setBlackness(color: Color, blackness: number): Color
Sets the color's blackness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the blackness of. |
blackness | number | The blackness as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.setBrightness(color: Color, brightness: number): Color
Sets the color's brightness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the brightness of. |
brightness | number | The brightness as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.setHue(color: Color, hue: integer): Color
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the hue of. |
hue | integer | The hue in degrees [0, 360]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.setLightness(color: Color, lightness: number): Color
Sets the color's lightness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the lightness of. |
lightness | number | The lightness as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.setSaturation(color: Color, saturation: number): Color
Sets the color's saturation.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the saturation of. |
saturation | number | The saturation as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.setWhiteness(color: Color, whiteness: number): Color
Sets the color's whiteness.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to set the whiteness of. |
whiteness | number | The whiteness as fraction [0, 1]. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The new color. |
function color.sub(value1: Color, value2: Color): Color
Parameters
| Name | Type | Description |
|---|
value1 | Color | The first color to subtract. |
value2 | Color | The second color to subtract. |
Returns
| Type | Name | Description |
|---|
Color | new_color | The result of the subtraction. |
function color.toCMYK(color: Color): number, number, number, number
Returns the color as CMYK values (cyan, magenta, yellow, black).
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert to CMYK. |
Returns
| Type | Name | Description |
|---|
number | cyan | The cyan as fraction [0, 1]. |
number | magenta | The magenta as fraction [0, 1]. |
number | yellow | The yellow as fraction [0, 1]. |
number | black | The black as fraction [0, 1]. |
function color.toHex(color: Color): string
Converts a color value to a hexadecimal string.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert. |
Returns
| Type | Name | Description |
|---|
string | | The hexadecimal representation of the color. |
function color.toHSL(color: Color): integer, number, number
Converts a color to HSL values (hue, saturation, lightness).
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert. |
Returns
| Type | Name | Description |
|---|
integer | hue | The hue in degrees [0, 360]. |
number | saturation | The saturation as fraction [0, 1]. |
number | lightness | The lightness as fraction [0, 1]. |
function color.toHSV(color: Color): integer, number, number
Returns the color as HSV values (hue, saturation, value).
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert. |
Returns
| Type | Name | Description |
|---|
integer | hue | The hue in degrees [0, 360]. |
number | saturation | The saturation as fraction [0, 1]. |
number | value | The value as fraction [0, 1]. |
function color.toHWB(color: Color): integer, number, number
Returns the color as HWB values (hue, whiteness, blackness).
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert to HWB. |
Returns
| Type | Name | Description |
|---|
integer | hue | The hue in degrees [0, 360]. |
number | whiteness | The whiteness as fraction [0, 1]. |
number | blackness | The blackness as fraction [0, 1]. |
function color.toRGB(color: Color): integer, integer, integer
Converts a color value to RGBA components.
Parameters
| Name | Type | Description |
|---|
color | Color | The color value to convert. |
Returns
| Type | Name | Description |
|---|
integer | red | The 8-bit red channel, in the range [0, 255]. |
integer | green | The 8-bit green channel, in the range [0, 255]. |
integer | blue | The 8-bit blue channel, in the range [0, 255]. |
function color.toString(color: Color): string
Returns the color as binary string.
Parameters
| Name | Type | Description |
|---|
color | Color | The color to convert. |
Returns
| Type | Name | Description |
|---|
string | binary_string | The color as binary string. |