---
title: "Kaboomers · Playground · Drew Minns"
description: "A noisy blank canvas for setting off comic-book explosions. Hold longer for a bigger one."
url: https://reallygood.work/playground/kaboomers/
---

Playground · 09

# Kaboomers

A noisy blank canvas. Press anywhere to set one off, and hold for a bigger one.

Click for a small one. Hold for a big one.

Grain

0.20

Lens

0.85

Dark cores

0.35

Biggest

0.72

Full hold

1.8s

Morph

0.90

How it works

Each explosion is two spiky outlines, an edge and a core, stored as a single row of a texture. A pixel’s colour is how far it sits between them, so every band of colour echoes the spikes.

While you hold, the outline redraws twelve times a second, the way hand-drawn animation boils. Let go and it pops on a spring. Then its spikes slowly lean, stretch and pull back as it shrinks and fades away.

Each pop behaves like a mass moving through spacetime. One wide front bends the light around it, smears it into its colours and slows as it travels, and when it reaches another explosion it shoves it, spins it and twists its spikes. The cursor is a soft glass lens over the whole thing.

The outside is always green. What’s inside is a roll of the dice, and about one in three comes up dark.

```js
// colour is the position between the core and the edge, so the bands follow the spikes
float t = clamp((r - inner) / max(outer - inner, .001), 0., 1.);
vec3 c = ramp(t);
float alpha = 1. - smoothstep(.74, 1., t);
```

Make it yourself

The whole thing in one file, with no libraries. Save it as an .html file and open it. The settings at the top follow the controls above, so tune it there, then copy.

kaboomers.html

```html
<!doctype html>
<meta charset="utf-8">
<title>Kaboomers</title>
<style>
  html, body { margin: 0; height: 100%; background: #20261a; overflow: hidden; }
  canvas { display: block; width: 100vw; height: 100vh; image-rendering: pixelated; touch-action: none; cursor: crosshair; }
</style>
<canvas id="board"></canvas>
<script>
const settings = {
  grain: 0.2,      // how much the noise shows (0 is none)
  lens: 0.85,        // how hard the glass under the cursor swells what's behind it
  dark: 0.35,        // the odds a burst comes up with a dark core
  biggest: 0.72,  // the biggest burst's radius, as a share of the screen's shorter side
  hold: 1.8,        // seconds of holding to reach the biggest
  morph: 0.9,      // how far the spikes lean and stretch as a burst ages (0 holds the launch shape)
};

const SMALLEST = 0.13, SAMPLES = 256, SCALE = 2;   // drawn at half size and scaled up, so the pixels stay crisp
const TAU = Math.PI * 2, BG = [32, 38, 26];
// colours, centre to edge. The outside is always green; what's inside is a roll of the dice
const LIGHT = [[238, 196, 58], [232, 168, 84], [212, 190, 226], [224, 204, 232], [88, 220, 200], [78, 158, 40]];
const DARK = [[8, 8, 8], [8, 8, 8], [240, 110, 40], [240, 236, 214], [170, 230, 60], [78, 158, 40]];

const canvas = document.getElementById('board'), ctx = canvas.getContext('2d');
let W, H, img;
function resize() {
  W = canvas.width = Math.ceil(innerWidth / SCALE); H = canvas.height = Math.ceil(innerHeight / SCALE);
  img = ctx.createImageData(W, H);
}
addEventListener('resize', resize); resize();

const rand = (a, b) => a + Math.random() * (b - a);
const mix = (a, b, t) => a + (b - a) * t;
const smooth = (a, b, x) => { const t = Math.max(0, Math.min(1, (x - a) / (b - a))); return t * t * (3 - 2 * t); };

// a spiky outline: random spikes around a circle, each falling away on both sides. The outline is the tallest one at each angle
function outline() {
  const n = Math.round(rand(13, 20));
  const spikes = Array.from({ length: n }, (_, i) => ({ at: (i + rand(-0.4, 0.4)) / n * TAU, h: rand(0.2, 1) ** 1.4, w: rand(0.06, 0.17) }));
  const edge = new Float32Array(SAMPLES);
  for (let i = 0; i < SAMPLES; i++) {
    const a = i / SAMPLES * TAU;
    for (const s of spikes) edge[i] = Math.max(edge[i], s.h * Math.exp(-Math.abs(Math.atan2(Math.sin(a - s.at), Math.cos(a - s.at))) / s.w));
    edge[i] = 0.2 + 0.8 * edge[i];
  }
  const peak = Math.max(...edge);
  return edge.map(v => v / peak);
}

// the ramp of six colours, from the core (0) to the edge (1)
function ramp(ink, t) {
  const x = t / 0.93 * 5, i = Math.min(Math.floor(x), 4), f = Math.min(1, x - i);
  return [0, 1, 2].map(k => mix(ink[i][k], ink[i + 1][k], f));
}

const bursts = [];
let pressing = null, mouse = null;
const at = e => ({ x: e.clientX / innerWidth, y: e.clientY / innerHeight });
// how charged a held burst is. The first moments of a hold count for the most
const charge = (b, now) => { const t = Math.min(1, (now - b.born) / 1000 / settings.hold); return 1 - (1 - t) * (1 - t); };

canvas.addEventListener('pointermove', e => { mouse = at(e); });
canvas.addEventListener('pointerleave', () => { mouse = null; });
canvas.addEventListener('pointerdown', e => {
  const dark = Math.random() < settings.dark, edge = outline();
  // the core is the same outline, smaller: a dark core fills most of the burst, a light one sits near the middle
  pressing = { ...at(e), edge, core: dark ? rand(0.74, 0.88) : rand(0.16, 0.34), ink: dark ? DARK : LIGHT, born: performance.now(), popped: 0, seed: rand(0, 40) };
  bursts.push(pressing);
});
addEventListener('pointerup', () => {
  if (!pressing) return;
  const p = charge(pressing, performance.now());
  pressing.size = mix(SMALLEST, settings.biggest, p);
  pressing.life = 9 + p * 7;   // bigger ones take longer to go
  pressing.popped = performance.now();
  pressing = null;
});

function draw(now) {
  const m = Math.min(W, H), t = now / 1000, d = img.data;
  // work out each burst's size, fade and morph for this frame
  for (let i = bursts.length - 1; i >= 0; i--) {
    const b = bursts[i];
    if (!b.popped) {   // still charging: shown smaller than it will pop to, and shaking
      b.r = mix(SMALLEST, settings.biggest, charge(b, now)) * 0.62 * m;
      b.cx = b.x * W + rand(-1, 1); b.cy = b.y * H + rand(-1, 1); b.fade = 1; b.bend = 0;
      continue;
    }
    const age = (now - b.popped) / 1000, through = age / b.life;
    if (through > 1) { bursts.splice(i, 1); continue; }
    const spring = 1 - 0.38 * Math.exp(-age * 9) * Math.cos(age * 20);   // pops on a spring, overshooting once
    b.r = b.size * m * spring * mix(1, 0.28, smooth(0.08, 1, through));   // then shrinks
    b.cx = b.x * W; b.cy = b.y * H;
    b.fade = 1 - smooth(0.3, 1, through);
    b.bend = settings.morph * smooth(0.25, 1.4, age);   // still at the moment of the pop, then slowly changing shape
  }

  const lensR = 0.24 * m;
  for (let y = 0, j = 0; y < H; y++) for (let x = 0; x < W; x++, j += 4) {
    let px = x, py = y, [r, g, bl] = BG;
    if (mouse) {   // the glass lens: pixels near the cursor look from closer to it, so what's under it swells
      const dx = x - mouse.x * W, dy = y - mouse.y * H, w = Math.exp(-(dx * dx + dy * dy) / (lensR * lensR * 0.42));
      px -= dx * w * 0.42 * settings.lens; py -= dy * w * 0.42 * settings.lens;
    }
    for (const b of bursts) {
      const dx = (px - b.cx) / b.r, dy = (py - b.cy) / b.r, dist = Math.hypot(dx, dy);
      if (dist > 1 + 0.5 * b.bend) continue;   // nowhere near this one
      let a = Math.atan2(dy, dx);
      a += b.bend * 0.15 * Math.sin(2 * a + t * 0.5 + b.seed);                                      // the spikes lean
      const stretch = 1 + b.bend * (0.16 * Math.sin(3 * a + t * 0.6 + b.seed) + 0.09 * Math.sin(5 * a - t * 0.4));   // and stretch
      const outer = b.edge[((Math.floor(a / TAU * SAMPLES) % SAMPLES) + SAMPLES) % SAMPLES] * stretch, inner = outer * b.core;
      // colour is how far between the core and the edge this pixel sits, so every band echoes the spikes
      const k = Math.min(1, Math.max(0, (dist - inner) / Math.max(outer - inner, 0.001)));
      const alpha = (1 - smooth(0.66, 1, k)) * b.fade;
      if (alpha <= 0) continue;
      const c = ramp(b.ink, k);
      r = mix(r, c[0], alpha); g = mix(g, c[1], alpha); bl = mix(bl, c[2], alpha);
    }
    // grain on top: a fresh roll for every pixel, every frame
    const n = (Math.random() + Math.random() + Math.random() - 1.5) * 120 * settings.grain;
    d[j] = r + n; d[j + 1] = g + n; d[j + 2] = bl + n; d[j + 3] = 255;
  }
  ctx.putImageData(img, 0, 0);
  requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
</script>
```

-   [Previous piece — Hallway](https://reallygood.work/playground/hallway/)
-   [Everything — All pieces](https://reallygood.work/playground/)
