@pbroom/color-kitManipulation

mixInto

Allocation-free mix(): writes the mix of color1 and color2 into out and returns it. Same semantics and bit-identical results as mix(), including the option-less OKLCH path. out may be the same object as either input, so mixInto(a, a, b, t) blends b into a in place.

functionimport { mixInto } from '@pbroom/color-kit';index.ts:243
function mixInto(
  out: Color,
  color1: Color,
  color2: Color,
  t?: number,
  options?: InterpolationOptions,
): Color;

Parameters

outColor
Color to write the result into
color1Color
First color; returned when t = 0
color2Color
Second color; returned when t = 1
t?numberdefault 0.5
Mix position (default 0.5)
options?InterpolationOptions
Interpolation space, hue method, and alpha handling (see mix())

Returns

Color

Example

TypeScript
import { mixInto, parse } from '@pbroom/color-kit';

const red = parse('#ff0000');
const lime = parse('#00ff00');
const out = { l: 0, c: 0, h: 0, alpha: 1 };
for (let i = 0; i <= 100; i++) {
  mixInto(out, red, lime, i / 100, { space: 'linear-srgb' });
  // ...use out without allocating per step
}