streak function

void streak(
  1. Painter p,
  2. double x,
  3. double y,
  4. double vx,
  5. double vy,
  6. int c, [
  7. double a = 1.0,
  8. double maxLen = 7.0,
  9. double glow = 0.4,
])

Implementation

void streak(
  Painter p,
  double x,
  double y,
  double vx,
  double vy,
  int c, [
  double a = 1.0,
  double maxLen = 7.0,
  double glow = 0.4,
]) {
  final rawSp = hypot(vx, vy);
  final sp = rawSp == 0.0 ? 1.0 : rawSp;
  final ux = vx / sp;
  final uy = vy / sp;
  final l = clamp(sp / 30.0, 1.0, maxLen);
  for (var d = l; d >= 0.0; d -= 0.5) {
    p.dot(
      x - ux * d,
      y - uy * d,
      d < 1.0 ? kWhite : (d < l * 0.5 ? c : scaleColor(c, 0.6)),
      (d < l * 0.5 ? 1.0 : 1.2 - d / l) * a,
    );
  }
  if (glow > 0.0) p.glow(x, y, 4, c, glow * a);
}