scorch function

void scorch(
  1. Painter p,
  2. List<int> hr,
  3. double t,
  4. double rx0,
  5. double cool,
  6. double fade, [
  7. int rows = 3,
])

The floor under a blast: a burn that spreads out in a blink, glows white-hot and cools through hr to soot.

Implementation

void scorch(
  Painter p,
  List<int> hr,
  double t,
  double rx0,
  double cool,
  double fade, [
  int rows = 3,
]) {
  if (fade <= 0.0) return;
  final rx = rx0 * math.min(1.0, t / 0.08);
  final ry = rows + 1.5;
  final n = hr.length;
  final x0 = (-rx).floor();
  final x1 = rx.ceil();
  for (var y = 0; y < rows; y++) {
    for (var x = x0; x <= x1; x++) {
      final dx = (x + 0.5) / rx;
      final dy = (y + 0.5) / ry;
      final d = math.sqrt(dx * dx + dy * dy);
      if (d > 1.0) continue;
      final k = rand(x * 31 + y, 3);
      final temp =
          math.pow(clamp(1.0 - t / cool), 1.4).toDouble() * (1.25 - d) - k * 0.35;
      final crack = k > 0.88 && d < 0.85
          ? math.pow(clamp(1.0 - t / (cool * 2.0)), 1.2).toDouble() *
              (1.15 - d) *
              0.8
          : 0.0;
      final h = math.max(temp, crack);
      if (h > 0.06) {
        final idx = math.min(n - 1, ((1.0 - math.min(1.0, h)) * (n - 1)).floor());
        final c = hr[idx];
        p.dot(x, y, c, fade);
        if ((x & 3) == 0 || crack > temp) {
          p.glow(x + 0.5, y, 6, c, 0.18 * h * fade);
        }
      } else {
        p.dot(x, y, d < 0.5 ? kExplosionSoot : kExplosionSoot2,
            (d < 0.95 - k * 0.3 ? 1.0 : 1.0 - d) * fade);
      }
    }
  }
}