Skip to content

color.palette.swatch

Summary

color.palette.swatch obtains one color by integer index. Use it to assign categorical colors to materials or geometry.

Syntax

swatch(palette: BuiltinPaletteName | ReadonlyArray<Color4>, index: number, alpha?: number): Color4
const accent = WasmGPU.color.palette.swatch("okabeito", 2);

Parameters

Name Type Required Description
palette BuiltinPaletteName | ReadonlyArray<Color4> Yes Built-in name or non-empty array of linear RGBA colors.
index number Yes Integer swatch index. Negative and oversized indices wrap modulo the palette size.
alpha number No Multiplier for the selected color's alpha. Defaults to 1 and must be in [0, 1].

Returns

Color4 - A fresh linear RGBA tuple. Built-in RGB is decoded from sRGB. Custom RGB channels are used as supplied. The selected tuple must contain four finite numbers. The same function is available as the named paletteSwatch export.

Example

const color = WasmGPU.color.palette.swatch("tab10", -1, 0.5);
console.log(color[3]); // 0.5

See Also