Skip to content

Should there be a lerp? #5

@makoConstruct

Description

@makoConstruct

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions