firePuff function

void firePuff(
  1. Painter p,
  2. double x,
  3. double y,
  4. double k,
  5. double size,
  6. double frac,
  7. List<int> hRamp, [
  8. double glowK = 0.18,
  9. double tx = 0.0,
  10. double ty = -1.0,
])

Implementation

void firePuff(
  Painter p,
  double x,
  double y,
  double k,
  double size,
  double frac,
  List<int> hRamp, [
  double glowK = 0.18,
  double tx = 0.0,
  double ty = -1.0,
]) {
  final age = 1.0 - k;
  final n = hRamp.length;
  final heat = math.min(0.999, math.pow(age, 0.62).toDouble() + frac * 0.1);
  final idx = math.min(n - 2, (heat * (n - 1)).floor());
  final r = size *
      (0.55 + 0.45 * math.min(1.0, age * 7.0)) *
      (1.0 - age * 0.55);
  final c = hRamp[idx];
  if (idx >= n - 2) {
    softDisc(p, x, y, r, c, math.min(1.0, k * 3.0) * 0.85);
    return;
  }
  solidDisc(p, x, y, r, hRamp[math.min(n - 1, idx + 2)]);
  if (r > 1.6 && ty > -0.99) {
    solidDisc(p, x + tx * r * 1.5, y + ty * r * 1.5, r * 0.3,
        hRamp[math.min(n - 1, idx + 1)]);
  }
  solidDisc(p, x - r * 0.16, y - r * 0.22, r * 0.78, c);
  if (r > 1.6) {
    solidDisc(p, x + tx * r * 0.9, y + ty * r * 0.9, r * 0.42, c);
  }
  if (idx <= 3 && r > 1.8) {
    solidDisc(
        p, x - r * 0.28, y - r * 0.34, r * 0.36, hRamp[math.max(0, idx - 1)]);
  }
  if (idx < 6) p.glow(x, y, r * 2.4 + 2.0, c, glowK * k);
}