color.map.fromStops¶
Summary¶
color.map.fromStops builds a continuous map from RGBA colors at specified positions. Choose the space used to interpolate between stops independently of the space used to encode the input colors.
Syntax¶
fromStops(stops: ReadonlyArray<ColormapStop>, desc?: ColormapDescriptor): Colormap
const map = WasmGPU.color.map.fromStops([[0, 0, 0, 1], [1, 1, 1, 1]]);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
stops |
ReadonlyArray<ColormapStop> |
Yes | At least two colors or positioned stops. Entries require four finite channels and explicit positions must be finite. |
desc |
ColormapDescriptor |
No | Table resolution, sampling filter, input color space and interpolation space. |
Returns¶
Colormap - Map backed by a sampled sRGB RGBA8 table. The equivalent class method is Colormap.fromStops.
Type Details¶
type ColormapStop = Color4 | { t: number; color: Color4 };
type ColormapDescriptor = {
resolution?: number;
filter?: ColormapFilter;
colorSpace?: ColormapColorSpace;
interpolation?: ColormapInterpolation;
};
type ColormapColorSpace = "srgb" | "linear";
type ColormapInterpolation = "srgb" | "linear" | "oklab";
resolution defaults to 256 and must be an integer from 2 through 8192. filter defaults to "linear" and can be "nearest". colorSpace and interpolation both default to "srgb". Alpha stays linear. All channels are clamped to [0, 1].
Bare colors are assigned positions by their index among bare entries divided by the total stop count minus one. Use only positioned stops when mixing explicit positions with regularly spaced colors. Stops are sorted and clamped to [0, 1]. A missing endpoint repeats the closest color. Repeated positions can create a sharp transition, with the visible edge affected by table resolution and the sampling filter.
Example¶
const map = WasmGPU.color.map.fromStops([
{ t: 0, color: [0.1, 0.2, 0.8, 1] },
{ t: 1, color: [0.95, 0.8, 0.1, 1] }
], { interpolation: "oklab" });
console.log(map.sampleCPU(0.5));