跳转到内容

Color

Color common color operations

Tutorial

colors

Constructors

new Color()

new Color(color?): Color

Parameters

color?: TColorArg

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

Returns

Color

Defined in

src/color/Color.ts:25

Properties

isUnrecognised

isUnrecognised: boolean = false

Defined in

src/color/Color.ts:19

Methods

getAlpha()

getAlpha(): number

Gets value of alpha channel for this color

Returns

number

0-1

Defined in

src/color/Color.ts:132


getSource()

getSource(): TRGBAColorSource

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

Returns

TRGBAColorSource

Defined in

src/color/Color.ts:63


overlayWith()

overlayWith(otherColor): Color

Overlays color with another color

Parameters

otherColor: string | Color

Returns

Color

thisArg

Defined in

src/color/Color.ts:172


setAlpha()

setAlpha(alpha): Color

Sets value of alpha channel for this color

Parameters

alpha: number

Alpha value 0-1

Returns

Color

thisArg

Defined in

src/color/Color.ts:141


setSource()

setSource(source): void

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

Parameters

source: TRGBAColorSource

Returns

void

Defined in

src/color/Color.ts:71


toBlackWhite()

toBlackWhite(threshold): Color

Transforms color to its black and white representation

Parameters

threshold: number

Returns

Color

thisArg

Defined in

src/color/Color.ts:160


toGrayscale()

toGrayscale(): Color

Transforms color to its grayscale representation

Returns

Color

thisArg

Defined in

src/color/Color.ts:150


toHex()

toHex(): string

Returns color representation in HEX format

Returns

string

ex: FF5555

Defined in

src/color/Color.ts:114


toHexa()

toHexa(): string

Returns color representation in HEXA format

Returns

string

ex: FF5555CC

Defined in

src/color/Color.ts:123


toHsl()

toHsl(): string

Returns color representation in HSL format

Returns

string

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

Defined in

src/color/Color.ts:96


toHsla()

toHsla(): string

Returns color representation in HSLA format

Returns

string

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

Defined in

src/color/Color.ts:105


toRgb()

toRgb(): string

Returns color representation in RGB format

Returns

string

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

Defined in

src/color/Color.ts:79


toRgba()

toRgba(): string

Returns color representation in RGBA format

Returns

string

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

Defined in

src/color/Color.ts:88


fromHex()

static fromHex(color): Color

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

Parameters

color: string

Color value ex: FF5555

Returns

Color

Static

Member Of

Color

Defined in

src/color/Color.ts:297


fromHsl()

static fromHsl(color): Color

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

Defined in

src/color/Color.ts:235


fromHsla()

static fromHsla(color): Color

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

Parameters

color: string

Returns

Color

Static

Function

Member Of

Color

Defined in

src/color/Color.ts:247


fromRgb()

static fromRgb(color): Color

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

Defined in

src/color/Color.ts:194


fromRgba()

static fromRgba(color): Color

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

Parameters

color: string

Returns

Color

Static

Function

Member Of

Color

Defined in

src/color/Color.ts:206


parseAngletoDegrees()

static parseAngletoDegrees(value): number

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

Defined in

src/color/Color.ts:333


sourceFromHex()

static sourceFromHex(color): undefined | TRGBAColorSource

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

Defined in

src/color/Color.ts:308


sourceFromHsl()

static sourceFromHsl(color): undefined | TRGBAColorSource

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

Defined in

src/color/Color.ts:259


sourceFromRgb()

static sourceFromRgb(color): undefined | TRGBAColorSource

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

Defined in

src/color/Color.ts:216