Better color lerping is the kind of thing I'd reach for a perceptual colorspace for, so I'm a little surprised to see that there doesn't seem to be a lerp function here.
Though I'm not sure how that would be implemented.
Right now, I'm using this:
double sign(double v) => v > 0 ? 1 : -1;
HSLuvColor lerpHsluv(HSLuvColor a, HSLuvColor b, double p) {
// find the shortest route through the hue circle
var forwards = (b.hue - a.hue);
var backwards = -(360 - forwards.abs()) * sign(forwards);
var huePath = forwards.abs() < backwards.abs() ? forwards : backwards;
return HSLuvColor.fromHSL(
(a.hue + p * huePath) % 360,
lerpDouble(a.saturation, b.saturation, p)!,
lerpDouble(a.lightness, b.lightness, p)!);
}
but of course, it does a kind of rainbow effect when the hues are far apart, which is not always going to be what people want.
Better color lerping is the kind of thing I'd reach for a perceptual colorspace for, so I'm a little surprised to see that there doesn't seem to be a lerp function here.
Though I'm not sure how that would be implemented.
Right now, I'm using this:
but of course, it does a kind of rainbow effect when the hues are far apart, which is not always going to be what people want.