hsluv-dart icon indicating copy to clipboard operation
hsluv-dart copied to clipboard

Should there be a lerp?

Open makoConstruct opened this issue 1 year ago • 1 comments

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.

makoConstruct avatar Oct 22 '24 04:10 makoConstruct

https://x.com/adamwathan/status/1846985442148946180?t=viDaxyStIMFhXadMr1SvaQ&s=19

https://www.fastcompany.com/3002676/magical-tech-behind-paper-ipads-color-mixing-perfection

bernaferrari avatar Oct 22 '24 05:10 bernaferrari