interpolate static method
Color
interpolate(
- Color start,
- Color end,
- double fraction, {
- bool shortestPath = true,
- InterpolationMethod method = InterpolationMethod.oklab,
Implementation
static Color interpolate(Color start, Color end, double fraction, {bool shortestPath = true, InterpolationMethod method = InterpolationMethod.oklab}) {
if (method == InterpolationMethod.oklab) {
final startLab = OkLab.fromColor(start);
final endLab = OkLab.fromColor(end);
return OkLab.lerp(startLab, endLab, fraction).toColor();
} else if (method == InterpolationMethod.okhsv) {
final startHsv = OkHsv.fromColor(start);
final endHsv = OkHsv.fromColor(end);
return OkHsv.lerp(startHsv, endHsv, fraction, shortestPath: shortestPath).toColor();
} else if (method == InterpolationMethod.okhsl) {
final startHsl = OkHsl.fromColor(start);
final endHsl = OkHsl.fromColor(end);
return OkHsl.lerp(startHsl, endHsl, fraction, shortestPath: shortestPath).toColor();
} else if (method == InterpolationMethod.oklch) {
final startLch = OkLch.fromColor(start);
final endLch = OkLch.fromColor(end);
return OkLch.lerp(startLch, endLch, fraction, shortestPath: shortestPath).toColor();
} else if (method == InterpolationMethod.hsv) {
HSVColor startHsv = HSVColor.fromColor(start);
HSVColor endHsv = HSVColor.fromColor(end);
double hue = lerpAngle(startHsv.hue, endHsv.hue, fraction, shortestPath: shortestPath, range: 360);
HSVColor lerpedColor = HSVColor.lerp(startHsv, endHsv, fraction)!.withHue(hue);
return lerpedColor.toColor();
} else {
return Color.lerp(start, end, fraction)!;
}
}