@pbroom/color-kit/planeQueries
samplePlaneGradient
Samples a two-color gradient and projects each sample onto the plane.
import { samplePlaneGradient } from '@pbroom/color-kit/plane';gradient.ts:55function samplePlaneGradient(
planeDefinition: PlaneDefinition,
query: Omit<PlaneGradientQuery, 'kind'>,
): PlaneGradientResult;Colors are interpolated in OKLCH along the shorter hue arc (a powerless hue borrows the other endpoint's), endpoints included. Each point carries its sampled color and plane x/y, clamped to the plane window; draw the path with toSvgPath. Works on every plane model.
Parameters
- planeDefinition
PlaneDefinition - Plane to project onto; a
Planeor anyPlaneDefinition. - query
Omit<PlaneGradientQuery, 'kind'> - Endpoints and sample count; see
PlaneGradientQuery.
Returns
PlaneGradientResultA new result with one point per sample.
Throws
- When
stepsis not a finite integer.
Example
import { parse, toHex } from '@pbroom/color-kit';
import { definePlane, samplePlaneGradient } from '@pbroom/color-kit/plane';
const plane = definePlane({ fixed: { h: 264 } });
const { points } = samplePlaneGradient(plane, {
from: parse('#1e3a8a'),
to: parse('#93c5fd'),
steps: 3,
});
points.map((point) => toHex(point.color)); // → ['#1e3a8a', '#527fc3', '#93c5fd']
points.map((point) => point.x.toFixed(3)); // → ['0.379', '0.594', '0.809']See also
sense for the fluent form.
Also exported from
@pbroom/color-kitthe same declaration, re-exported