interpolateRgbGamma function

String Function(num) Function(Object?, Object?) interpolateRgbGamma(
  1. num y
)

Returns a new RGB color space interpolator factory using the specified gamma.

For example, to interpolate from purple to orange with a corrected gamma of 2.2:

final interpolator = interpolateRgbGamma(2.2)("purple", "orange");
rgbGamma

See Eric Brasseur’s article, Gamma error in picture scaling, for more on gamma correction.

Implementation

String Function(num) Function(Object?, Object?) interpolateRgbGamma(num y) {
  var color = gamma(y);
  return (start, end) {
    var r = color((start = Rgb.from(start)).r, (end = Rgb.from(end)).r),
        g = color((start as Rgb).g, (end as Rgb).g),
        b = color(start.b, end.b),
        opacity = nogamma(start.opacity, end.opacity);
    return (t) {
      (start as Rgb).r = r(t);
      start.g = g(t);
      start.b = b(t);
      start.opacity = opacity(t);
      return start.toString();
    };
  };
}