slash function

void slash(
  1. Painter p,
  2. Swing s,
  3. double t, [
  4. int half = 0,
])

A slash crescent along swing s (Sprite Fusion's recipe).

Implementation

void slash(Painter p, Swing s, double t, [int half = 0]) {
  final u = t - s.t0;
  if (u < 0.0) return;
  final rampList = s.ramp;
  final n = rampList.length;
  final life = s.sweep + s.hold + s.trail;
  final hot = s.hot;
  final head = Ease.outExpo(clamp(u / s.sweep));
  final tail = smooth(s.sweep + s.hold, life, u);
  final age = clamp(u / life);
  final uEnd = s.span * head;
  final tStart = s.span * tail;
  final wMax = s.w * (1.0 - tail * 0.55);
  if (tail < 1.0 && uEnd - tStart > 0.01) {
    smear(p, s, tStart, uEnd, wMax, (uu, r, out, _) {
      final v = (uu - tStart) / (uEnd - tStart);
      final sinTerm = math.max(
        0.0,
        math.sin(math.pi * math.pow(v, s.lens ? 1.0 : 2.2)),
      );
      final w = wMax * math.pow(sinTerm, s.lens ? 0.75 : 0.6);
      if (w < 0.35) return;
      final q = (s.r - r) / w;
      if (q < 0.0 || q > 1.0) return;
      final ci = (q < 0.22 && age < 0.5) || q < hot * 0.7
          ? 0
          : (q * (n - 1) * 0.75 + age * 2.4 - v * 0.8 + 0.4 - hot * 3.0 + 0.5)
              .floor();
      out.c = rampList[n - 1 - clampInt(ci, 0, n - 1)];
      out.a = math.min(1.0, v / (s.lens ? 0.1 : 0.4));
    }, half: half);
    glowAlong(
      p,
      s,
      s.r - wMax * 0.4,
      tStart,
      uEnd,
      5.0 + wMax,
      rampList[n - 3],
      0.0,
      kFn: (uu) =>
          (0.22 + hot * 0.3) * (1.0 - age) * ((uu - tStart) / (uEnd - tStart)),
      half: half,
      step: 0.3,
    );
  }
  final th = 0.7 * (1.0 - clamp((u - s.sweep - s.hold) / (s.trail + 0.2)));
  if (tail > 0.02 && th > 0.0) {
    trace(
      p,
      s,
      s.r - 0.5,
      0.0,
      tStart,
      rampList[2],
      0.0,
      aFn: (uu) => th * (0.4 + 0.6 * uu / s.span),
      half: half,
    );
  }
}