Interpolate colors in the current colorMode or in another specified space - #9024
Merged
Conversation
Contributor
|
Nice screenshots @dontwanttothink! |
dontwanttothink
force-pushed
the
main
branch
2 times, most recently
from
August 9, 2026 14:33
bf3701d to
31c831a
Compare
Contributor
Author
|
I can't get the tests to run in my computer (I even tried setting up a Linux VM), so I'm not sure why it's failing to write those seemingly unrelated images :( |
Contributor
Author
|
Oh, it looks like it's fixed? |
Contributor
Author
|
Apparently the tests passed in my fork 🧚 |
Or in another specified space
I ran this script:
```ts
import Color from "colorjs.io";
const $ = console.log;
// The tests go:
// fromColor = mockP5Prototype.color(218, 165, 32);
// toColor = mockP5Prototype.color(72, 61, 139);
// so create the same colours
const fromColor = new Color("rgb(218 165 32)");
const toColor = new Color("rgb(72 61 139)");
$("HSL lerp test:");
$(String(fromColor.range(toColor, {
space: "hsl",
outputSpace: "hsl"
})(0.33)));
$(String(fromColor.range(toColor, {
space: "hsl",
outputSpace: "hsl"
})(0.66)));
$();
$("HSB lerp test:");
$(String(fromColor.range(toColor, {
space: "hsv", // see https://en.wikipedia.org/wiki/HSL_and_HSV#:~:text=HSV%20stands%20for%20hue%2C%20saturation%2C%20and%20value%2C%20and%20is%20also%20often%20called%20HSB
})(0.33)));
$(String(fromColor.range(toColor, {
space: "hsv",
})(0.66)));
const fromColorA = new Color(`rgb(218 165 32 / ${49 / 255})`);
const toColorA = new Color(`rgb(72 61 139 / ${200 / 255})`);
$();
$("HSLA lerp test:");
$(String(fromColorA.range(toColorA, {
space: "hsl",
})(0.33)));
$(String(fromColorA.range(toColorA, {
space: "hsl",
})(0.66)));
$();
$("HSBA lerp test");
$(String(fromColorA.range(toColorA, {
space: "hsv",
})(0.33)));
$(String(fromColorA.range(toColorA, {
space: "hsv",
})(0.66)));
```
to get this output:
```css
HSL lerp test:
hsl(351.94 62.718% 45.784%)
hsl(300.97 51.036% 42.549%)
HSB lerp test:
color(--hsv 351.94 75.683% 75.267%)
color(--hsv 300.97 66.045% 65.043%)
HSLA lerp test:
hsl(351.94 62.718% 45.784% / 0.38757)
hsl(300.97 51.036% 42.549% / 0.58298)
HSBA lerp test
color(--hsv 351.94 75.683% 75.267% / 0.38757)
color(--hsv 300.97 66.045% 65.043% / 0.58298)
```
davepagurek
approved these changes
Aug 12, 2026
davepagurek
left a comment
Contributor
There was a problem hiding this comment.
@limzykenneth I think this looks good to me, anything you see that needs updating before merging?
Member
|
All looks great, well done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #8806 and resolves #8883
Changes:
This pull request is an implementation of #8806 (comment):
Screenshots of the change:
The following outputs are produced by variations of this code:
RGB:

LAB:

HSL:

I also tested the options object overload:
Compare to HSB interpolation:
PR Checklist
npm run lintpasses