applyInterpolation method

  1. @override
void applyInterpolation(
  1. ActorComponent? component,
  2. double time,
  3. KeyFrame toFrame,
  4. double mix,
)
override

Implementation

@override
void applyInterpolation(
    ActorComponent? component, double time, KeyFrame toFrame, double mix) {
  RadialGradientColor radial = component as RadialGradientColor;
  Float32List v = (toFrame as KeyFrameRadial)._value;

  double f =
      _interpolator.getEasedMix((time - _time) / (toFrame.time - _time));
  double fi = 1.0 - f;

  int ridx = 0;
  int wi = 0;

  if (mix == 1.0) {
    radial.secondaryRadiusScale = _value[ridx] * fi + v[ridx++] * f;
    radial.start[0] = _value[ridx] * fi + v[ridx++] * f;
    radial.start[1] = _value[ridx] * fi + v[ridx++] * f;
    radial.end[0] = _value[ridx] * fi + v[ridx++] * f;
    radial.end[1] = _value[ridx] * fi + v[ridx++] * f;

    while (ridx < v.length && wi < radial.colorStops.length) {
      radial.colorStops[wi++] = _value[ridx] * fi + v[ridx++] * f;
    }
  } else {
    double imix = 1.0 - mix;

    // Mix : first interpolate the KeyFrames,
    //  and then mix on top of the current value.
    double val = _value[ridx] * fi + v[ridx] * f;
    radial.secondaryRadiusScale = _value[ridx] * fi + v[ridx++] * f;
    val = _value[ridx] * fi + v[ridx] * f;
    radial.start[0] = _value[ridx++] * imix + val * mix;
    val = _value[ridx] * fi + v[ridx] * f;
    radial.start[1] = _value[ridx++] * imix + val * mix;
    val = _value[ridx] * fi + v[ridx] * f;
    radial.end[0] = _value[ridx++] * imix + val * mix;
    val = _value[ridx] * fi + v[ridx] * f;
    radial.end[1] = _value[ridx++] * imix + val * mix;

    while (ridx < v.length && wi < radial.colorStops.length) {
      val = _value[ridx] * fi + v[ridx] * f;
      radial.colorStops[wi] = radial.colorStops[wi] * imix + val * mix;

      ridx++;
      wi++;
    }
  }
  radial.markPaintDirty();
}