apply method

  1. @override
void apply(
  1. ActorComponent? component,
  2. double mix
)
override

Implementation

@override
void apply(ActorComponent? component, double mix) {
  GradientColor gradient = component as GradientColor;

  int ridx = 0;
  int wi = 0;

  if (mix == 1.0) {
    gradient.start[0] = _value[ridx++];
    gradient.start[1] = _value[ridx++];
    gradient.end[0] = _value[ridx++];
    gradient.end[1] = _value[ridx++];

    while (ridx < _value.length && wi < gradient.colorStops.length) {
      gradient.colorStops[wi++] = _value[ridx++];
    }
  } else {
    double imix = 1.0 - mix;
    gradient.start[0] = gradient.start[0] * imix + _value[ridx++] * mix;
    gradient.start[1] = gradient.start[1] * imix + _value[ridx++] * mix;
    gradient.end[0] = gradient.end[0] * imix + _value[ridx++] * mix;
    gradient.end[1] = gradient.end[1] * imix + _value[ridx++] * mix;

    while (ridx < _value.length && wi < gradient.colorStops.length) {
      gradient.colorStops[wi] =
          gradient.colorStops[wi] * imix + _value[ridx++];
      wi++;
    }
  }
  gradient.markPaintDirty();
}