Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should there be a lerp? #5

Open
makoConstruct opened this issue Oct 22, 2024 · 1 comment
Open

Should there be a lerp? #5

makoConstruct opened this issue Oct 22, 2024 · 1 comment

Comments

@makoConstruct
Copy link

makoConstruct commented Oct 22, 2024

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.

@bernaferrari
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants