lerp method

HSVColor lerp (HSVColor a, HSVColor b, double t)

Linearly interpolate between two HSVColors.

The colors are interpolated by interpolating the alpha, hue, saturation, and value channels separately, which usually leads to a more pleasing effect than Color.lerp (which interpolates the red, green, and blue channels separately).

If either color is null, this function linearly interpolates from a transparent instance of the other color. This is usually preferable to interpolating from Colors.transparent (const Color(0x00000000)) since that will interpolate from a transparent red and cycle through the hues to match the target color, regardless of what that color's hue is.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

Values outside of the valid range for each channel will be clamped.


static HSVColor lerp(HSVColor a, HSVColor b, double t) {
  assert(t != null);
  if (a == null && b == null)
    return null;
  if (a == null)
    return b._scaleAlpha(t);
  if (b == null)
    return a._scaleAlpha(1.0 - t);
  return HSVColor.fromAHSV(
    lerpDouble(a.alpha, b.alpha, t).clamp(0.0, 1.0),
    lerpDouble(a.hue, b.hue, t) % 360.0,
    lerpDouble(a.saturation, b.saturation, t).clamp(0.0, 1.0),
    lerpDouble(a.value, b.value, t).clamp(0.0, 1.0),