Skip to main content

Class: ManimColor

Defined in: src/utils/ManimColor.ts:103

Internal color data structure, ported from ManimCE's ManimColor.

The internal representation is an [r,g,b,a] array of floats in 0.0..1.0.

Extended by​

Constructors​

Constructor​

new ManimColor(value, alpha): ManimColor

Defined in: src/utils/ManimColor.ts:111

Parameters​

value​

ParsableManimColor

Any ParsableManimColor, or null for black.

alpha​

number = 1.0

Opacity in 0.0..1.0. Default 1.0. Ignored for an 8-digit hex string and for a 4-element (RGBA) array, which carry their own alpha.

Returns​

ManimColor

Properties​

value​

protected readonly value: Rgba

Defined in: src/utils/ManimColor.ts:104

Methods​

constructFromSpace()​

protected constructFromSpace(space): ManimColor

Defined in: src/utils/ManimColor.ts:144

Build a color of this class from a space array. Overridden by subclasses.

Parameters​

space​

number[]

Returns​

ManimColor


darker()​

darker(blend): ManimColor

Defined in: src/utils/ManimColor.ts:237

Return a darker color: interpolated toward black. The opacity is unchanged.

Parameters​

blend​

number = 0.2

0.0 (unchanged) to 1.0 (pure black). Default 0.2.

Returns​

ManimColor


equals()​

equals(other): boolean

Defined in: src/utils/ManimColor.ts:257

Compare two colors with a numpy-style allclose tolerance.

Parameters​

other​

ManimColor

Returns​

boolean


fromInternal()​

protected fromInternal(rgba): ManimColor

Defined in: src/utils/ManimColor.ts:149

Build a color of this class from an [r,g,b,a] value (ManimCE _from_internal).

Parameters​

rgba​

Rgba

Returns​

ManimColor


getSpace()​

protected getSpace(): number[]

Defined in: src/utils/ManimColor.ts:138

The space used for operators and interpolation ([r,g,b,a] for the base).

Returns​

number[]


internalRgba()​

protected internalRgba(): Rgba

Defined in: src/utils/ManimColor.ts:133

The [r,g,b,a] internal value. Overridden by subclasses.

Returns​

Rgba


interpolate()​

interpolate(other, alpha): ManimColor

Defined in: src/utils/ManimColor.ts:200

Interpolate toward other in this color's space.

alpha 0.0 returns a copy of this color, 1.0 returns other.

Parameters​

other​

ManimColor

alpha​

number

Returns​

ManimColor


invert()​

invert(withAlpha): ManimColor

Defined in: src/utils/ManimColor.ts:211

Return a linearly inverted color (1 - channel).

Parameters​

withAlpha​

boolean = false

If true, the alpha is inverted too. Default false.

Returns​

ManimColor


lighter()​

lighter(blend): ManimColor

Defined in: src/utils/ManimColor.ts:248

Return a lighter color: interpolated toward white. The opacity is unchanged.

Parameters​

blend​

number = 0.2

0.0 (unchanged) to 1.0 (pure white). Default 0.2.

Returns​

ManimColor


opacity()​

opacity(opacity): ManimColor

Defined in: src/utils/ManimColor.ts:221

Return a new color with the given opacity and the same color values.

Parameters​

opacity​

number

Returns​

ManimColor


toHex()​

toHex(withAlpha): string

Defined in: src/utils/ManimColor.ts:182

Convert to a #RRGGBB hex string, or #RRGGBBAA when withAlpha is true.

Parameters​

withAlpha​

boolean = false

Returns​

string


toHsv()​

toHsv(): Hsv

Defined in: src/utils/ManimColor.ts:189

Convert to an [h,s,v] float array (0.0..1.0).

Returns​

Hsv


toIntRgb()​

toIntRgb(): Rgb

Defined in: src/utils/ManimColor.ts:168

Convert to an [r,g,b] integer array (0..255, truncated).

Returns​

Rgb


toIntRgba()​

toIntRgba(): Rgba

Defined in: src/utils/ManimColor.ts:174

Convert to an [r,g,b,a] integer array (0..255, truncated).

Returns​

Rgba


toRgb()​

toRgb(): Rgb

Defined in: src/utils/ManimColor.ts:156

Convert to an [r,g,b] float array (0.0..1.0).

Returns​

Rgb


toRgba()​

toRgba(): Rgba

Defined in: src/utils/ManimColor.ts:162

Convert to an [r,g,b,a] float array (0.0..1.0).

Returns​

Rgba


toString()​

toString(): string

Defined in: src/utils/ManimColor.ts:264

Return the #RRGGBB hex string, so a color interpolates into templates.

Returns​

string


withAlpha()​

withAlpha(alpha): ManimColor

Defined in: src/utils/ManimColor.ts:228

Alias of opacity.

Parameters​

alpha​

number

Returns​

ManimColor


fromHex()​

static fromHex(hex, alpha): ManimColor

Defined in: src/utils/ManimColor.ts:281

Create a color from a hex string. Ports ManimColor.from_hex.

Parameters​

hex​

string

alpha​

number = 1.0

Returns​

ManimColor


fromHsv()​

static fromHsv(hsv, alpha): ManimColor

Defined in: src/utils/ManimColor.ts:286

Create a color from an [h,s,v] float array. Ports ManimColor.from_hsv.

Parameters​

hsv​

Hsv

alpha​

number = 1.0

Returns​

ManimColor


fromRgb()​

static fromRgb(rgb, alpha): ManimColor

Defined in: src/utils/ManimColor.ts:271

Create a color from an RGB(A) float array. Ports ManimColor.from_rgb.

Parameters​

rgb​

Rgb | Rgba

alpha​

number = 1.0

Returns​

ManimColor


fromRgba()​

static fromRgba(rgba): ManimColor

Defined in: src/utils/ManimColor.ts:276

Create a color from an RGBA float array. Ports ManimColor.from_rgba.

Parameters​

rgba​

Rgba

Returns​

ManimColor


parse()​

static parse(color, alpha): ManimColor | ManimColor[]

Defined in: src/utils/ManimColor.ts:299

Parse one color, or a list of colors.

A numeric array (length 3 or 4) is read as a single RGB(A) color. An array whose elements are themselves colors (strings, numbers-as-ints via nested arrays, or ManimColors) is read as a list. This resolves ManimCE's documented "array of numbers becomes a list of colors" footgun in favor of the single-color reading.

Parameters​

color​

ParsableManimColor | ParsableManimColor[]

alpha​

number = 1.0

Returns​

ManimColor | ManimColor[]