Skip to content

Color

Defined in: src/color/Color.ts:17

Color common color operations

Tutorial

colors

Constructors

new Color()

new Color(color?): Color

Defined in: src/color/Color.ts:25

Parameters

color?

TColorArg

optional in hex or rgb(a) or hsl format or from known color list

Returns

Color

Properties

isUnrecognised

isUnrecognised: boolean = false

Defined in: src/color/Color.ts:19

Methods

getAlpha()

getAlpha(): number

Defined in: src/color/Color.ts:133

Gets value of alpha channel for this color

Returns

number

0-1


getSource()

getSource(): TRGBAColorSource

Defined in: src/color/Color.ts:64

Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])

Returns

TRGBAColorSource


overlayWith()

overlayWith(otherColor): Color

Defined in: src/color/Color.ts:173

Overlays color with another color

Parameters

otherColor

string | Color

Returns

Color

thisArg


setAlpha()

setAlpha(alpha): Color

Defined in: src/color/Color.ts:142

Sets value of alpha channel for this color

Parameters

alpha

number

Alpha value 0-1

Returns

Color

thisArg


setSource()

setSource(source): void

Defined in: src/color/Color.ts:72

Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])

Parameters

source

TRGBAColorSource

Returns

void


toBlackWhite()

toBlackWhite(threshold): Color

Defined in: src/color/Color.ts:161

Transforms color to its black and white representation

Parameters

threshold

number

Returns

Color

thisArg


toGrayscale()

toGrayscale(): Color

Defined in: src/color/Color.ts:151

Transforms color to its grayscale representation

Returns

Color

thisArg


toHex()

toHex(): string

Defined in: src/color/Color.ts:115

Returns color representation in HEX format

Returns

string

ex: FF5555


toHexa()

toHexa(): string

Defined in: src/color/Color.ts:124

Returns color representation in HEXA format

Returns

string

ex: FF5555CC


toHsl()

toHsl(): string

Defined in: src/color/Color.ts:97

Returns color representation in HSL format

Returns

string

ex: hsl(0-360,0%-100%,0%-100%)


toHsla()

toHsla(): string

Defined in: src/color/Color.ts:106

Returns color representation in HSLA format

Returns

string

ex: hsla(0-360,0%-100%,0%-100%,0-1)


toRgb()

toRgb(): string

Defined in: src/color/Color.ts:80

Returns color representation in RGB format

Returns

string

ex: rgb(0-255,0-255,0-255)


toRgba()

toRgba(): string

Defined in: src/color/Color.ts:89

Returns color representation in RGBA format

Returns

string

ex: rgba(0-255,0-255,0-255,0-1)


fromHex()

static fromHex(color): Color

Defined in: src/color/Color.ts:298

Returns new color object, when given a color in HEX format

Parameters

color

string

Color value ex: FF5555

Returns

Color

Static

Member Of

Color


fromHsl()

static fromHsl(color): Color

Defined in: src/color/Color.ts:236

Returns new color object, when given a color in HSL format

Parameters

color

string

Color value ex: hsl(0-260,0%-100%,0%-100%)

Returns

Color

Member Of

Color


fromHsla()

static fromHsla(color): Color

Defined in: src/color/Color.ts:248

Returns new color object, when given a color in HSLA format

Parameters

color

string

Returns

Color

Static

Function

Member Of

Color


fromRgb()

static fromRgb(color): Color

Defined in: src/color/Color.ts:195

Returns new color object, when given a color in RGB format

Parameters

color

string

Color value ex: rgb(0-255,0-255,0-255)

Returns

Color

Member Of

Color


fromRgba()

static fromRgba(color): Color

Defined in: src/color/Color.ts:207

Returns new color object, when given a color in RGBA format

Parameters

color

string

Returns

Color

Static

Function

Member Of

Color


parseAngletoDegrees()

static parseAngletoDegrees(value): number

Defined in: src/color/Color.ts:334

Converts a string that could be any angle notation (50deg, 0.5turn, 2rad) into degrees without the ‘deg’ suffix

Parameters

value

string

ex: 0deg, 0.5turn, 2rad

Returns

number

number in degrees or NaN if inputs are invalid

Static

Member Of

Color


sourceFromHex()

static sourceFromHex(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:309

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in HEX format

Parameters

color

string

ex: FF5555 or FF5544CC (RGBa)

Returns

undefined | TRGBAColorSource

source

Static

Member Of

Color


sourceFromHsl()

static sourceFromHsl(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:260

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in HSL or HSLA format. Adapted from https://github.com/mjijackson

Parameters

color

string

Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)

Returns

undefined | TRGBAColorSource

source

Member Of

Color

See

http://http://www.w3.org/TR/css3-color/#hsl-color


sourceFromRgb()

static sourceFromRgb(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:217

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in RGB or RGBA format

Parameters

color

string

Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)

Returns

undefined | TRGBAColorSource

source

Member Of

Color