Interpolate a color palette

Generate a fixed sequence between two endpoints in one declared color space.

0 to 0.33 0 0.17 0.33
0.50 to 0.83 0.50 0.67 0.83
Endpoint 1
7 colors
6 equal intervals
space: Oklab

Control both endpoints and the number of colors

The result includes the violet and orange endpoints plus five equally positioned Oklab mixes between them.

Generate the complete sequence once

ColorPalette::interpolate() places each color at i divided by steps minus one and returns an unnamed ordered palette.

<?php

use PhpColor\Color\Color;
use PhpColor\Color\Palette\ColorPalette;

$palette = ColorPalette::interpolate(
    Color::parse('#7c3aed'),
    Color::parse('#f59e0b'),
    steps: 7,
    space: 'oklab',
);

echo implode(', ', $palette->toHex());

// #7c3aed, #8b59d7, #9d6dbf, #b17da6, #c78a88, #dd9561, #f59e0b
use PhpColor\Color\Color; use PhpColor\Color\Palette\ColorPalette; $palette = ColorPalette::interpolate( Color::parse('#7c3aed'), Color::parse('#f59e0b'), steps: 7, space: 'oklab', ); echo implode(', ', $palette->toHex()); // #7c3aed, #8b59d7, #9d6dbf, #b17da6, #c78a88, #dd9561, #f59e0b

Interpolation space changes the path

The endpoints and positions can stay identical while another supported interpolation space produces different intermediate colors.

MinimumThe method requires at least two steps.
EndpointsThe first and last palette entries are the supplied colors.
PositionsIntermediate positions are evenly distributed.
GamutVerify the representation used for the target display or storage format.

Choose a next step

Choose the endpoints, space, and exact sequence length