colorLerp function
Returns a function that interpolates between two colors.
The returned function accepts a parameter betwee 0 and 1, being 0 the first color and 1 the second color.
ex:
final lerp = colorLerp(TrueColor(255, 0, 0), TrueColor(0, 255, 0));
final color = lerp(0.5); // color is TrueColor(127, 127, 0)
Implementation
LerpFunction colorLerp(TrueColor color1, TrueColor color2) {
TrueColor lerp(double t) {
final value = t.clamp(0.0, 1.0);
final r = (color1.r + (color2.r - color1.r) * value).round();
final g = (color1.g + (color2.g - color1.g) * value).round();
final b = (color1.b + (color2.b - color1.b) * value).round();
return TrueColor(r, g, b);
}
return lerp;
}