Skip to content

@simversus/yjvis


@simversus/yjvis / math / Color

Class: Color

Defined in: math/Color.ts:164

颜色类,用于表示 RGB 颜色

Extended by

Constructors

Constructor

new Color(r?, g?, b?): Color

Defined in: math/Color.ts:190

构造函数

Parameters

r?

ColorRepresentation

r 通道值 (0-1)、Color对象、十六进制颜色值或 CSS 颜色字符串

g?

number

g 通道值 (0-1)

b?

number

b 通道值 (0-1)

Returns

Color

Properties

b

b: number = 1

Defined in: math/Color.ts:172

蓝色通道 (0-1)


g

g: number = 1

Defined in: math/Color.ts:170

绿色通道 (0-1)


isColor

isColor: boolean = true

Defined in: math/Color.ts:175

颜色对象标识


r

r: number = 1

Defined in: math/Color.ts:168

红色通道 (0-1)

Accessors

elements

Get Signature

get elements(): Number3

Defined in: math/Color.ts:180

获取 [r, g, b] 数组

Returns

Number3

Methods

[iterator]()

[iterator](): Generator<number, void, unknown>

Defined in: math/Color.ts:408

Returns

Generator<number, void, unknown>


applyMatrix3()

applyMatrix3(m): Color

Defined in: math/Color.ts:379

应用 3x3 矩阵变换颜色

Parameters

m

Mat3

变换矩阵

Returns

Color

this


clone()

clone(): Color

Defined in: math/Color.ts:346

克隆当前颜色

Returns

Color

新的 Color 实例


convertLinearToSRGB()

convertLinearToSRGB(color): Color

Defined in: math/Color.ts:367

将线性空间转换到 sRGB 颜色空间

Parameters

color

Color = ...

源颜色 (默认为当前颜色)

Returns

Color

this


convertSRGBToLinear()

convertSRGBToLinear(color): Color

Defined in: math/Color.ts:355

将 sRGB 颜色空间转换到线性空间

Parameters

color

Color = ...

源颜色 (默认为当前颜色)

Returns

Color

this


copy()

copy(color): Color

Defined in: math/Color.ts:335

复制另一个颜色的值

Parameters

color

Color

源颜色对象

Returns

Color

this


getHex()

getHex(): number

Defined in: math/Color.ts:275

获取十六进制颜色值

Returns

number

十六进制数值,如 0xff0000


getRGB()

getRGB(target, colorSpace): Color

Defined in: math/Color.ts:248

获取 RGB 值到目标 Color 对象

Parameters

target

Color

目标 Color 对象

colorSpace

ColorSpace = ColorManagement.workingColorSpace

颜色空间(暂时未完全使用)

Returns

Color

目标 Color 对象


random()

random(): Color

Defined in: math/Color.ts:388

将颜色设置为随机值

Returns

Color

this


scale()

scale(s): Color

Defined in: math/Color.ts:319

缩放颜色值

Parameters

s

number

缩放系数

Returns

Color

this


set()

set(r, g?, b?): Color

Defined in: math/Color.ts:208

设置颜色

Parameters

r

ColorRepresentation

r 通道值、Color对象、数组、十六进制值或字符串

g?

number

g 通道值

b?

number

b 通道值

Returns

Color

this


setHex()

setHex(hex): Color

Defined in: math/Color.ts:262

从十六进制数值设置颜色

Parameters

hex

number

十六进制颜色值,如 0xff0000

Returns

Color

this


setRGB()

setRGB(r, g, b, colorSpace): Color

Defined in: math/Color.ts:234

使用 RGB 值设置颜色

Parameters

r

number

红色通道 (0-1)

g

number

绿色通道 (0-1)

b

number

蓝色通道 (0-1)

colorSpace

ColorSpace = ColorManagement.workingColorSpace

颜色空间(暂时未完全使用)

Returns

Color

this


setStyle()

setStyle(style): Color

Defined in: math/Color.ts:298

从 CSS 风格字符串设置颜色 (支持 #RRGGBB, #RGB)

Parameters

style

string

CSS 颜色字符串

Returns

Color

this


toArray()

toArray(array, offset): number[] | TypedArray

Defined in: math/Color.ts:401

将颜色转换为数组

Parameters

array

目标数组

number[] | TypedArray

offset

number = 0

偏移量

Returns

number[] | TypedArray

目标数组