Interactive Vision From Zero · Episode 16
Body Finale
Body Finale is Episode 16 of Interactive Vision From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.
Part of the MasterAllArts Creative 3D Roadmap .
Stand up. Throw your arms over your head — the screen bursts. Sweep your hands through the air and they leave ribbons of light behind them. Fling your arms wide and a shockwave rings out across the room. Bring your palms together and everything gets pulled into your chest like you're collapsing a star. And the whole time, it's singing — a soft pentatonic note on every gesture, louder when you move fast. This is the Season 2 capstone: a full-body interactive installation that you paint, conduct, and play with nothing but your body in front of a webcam.
The installation below is already performing with no camera on. A synthetic body — the same 33-landmark figure from the last seven episodes — is dancing a little routine: it raises its arms and fires a burst, throws them wide for a shockwave, claps for a pull-in, sweeps to draw trails, all on a loop, so the piece plays itself the instant the page loads. Step through the six stages with the dropdown to watch the machine get built one layer at a time. Then tap enable sound, hit use my camera, and the installation becomes yours — the same bursts, trails, shockwaves, and notes, driven by your real body.
What you're looking at
That glowing figure is a body — synthetic, built from the exact 33-landmark structure MediaPipe Pose emits, so every effect below runs unchanged on a real webcam. It's alive on first paint with no camera: the synthetic body performs a looping routine — arms up, arms wide, clap, sweep — and the installation reacts to each pose in real time. This is the whole point of the series' synthetic-driver convention, cashed in for the finale: the art performs itself before you ever grant a camera, and the instant you do, the identical pipeline starts reading you instead.
One convention up front, because it's the number-one source of "why is it backwards"
confusion: this is a selfie view, so we mirror the X axis. Every
landmark is plotted at (1 - x) * width, and we apply that same flip to the
synthetic body, so when you raise your right hand the light rises on the right of the
screen. Camera and synthetic modes stay in perfect lockstep — the mirror is the only
thing standing between "intuitive" and "infuriating."
And one promise about your privacy, stated plainly because it matters: 🔒 everything runs on-device. The pose model is downloaded to your browser and runs locally on your machine; no video frame, no landmark, no audio ever leaves your computer. An installation you can trust in your own living room.
This episode is a composition, not a new primitive — it ties together everything Season 2 taught: the pose skeleton (Ep 09), the avatar mapping instinct (Ep 10), the hysteresis state machine that counted reps (Ep 11), the particle/trail brushes from Season 1's light-painting and air-instrument finales (Ep 07–08). Step through the six stages and watch the installation assemble itself.
Stage 1 — The body as light
We start by throwing away the stick-figure skeleton and rendering the body as a field of light. Along every bone — shoulder to elbow, hip to knee — we sprinkle soft, additive particles, brightest at the joints. Where limbs cross, the additive blending stacks up and glows hotter. The result is a silhouette made of stars that breathes as the body moves: not a diagram of a person, but a luminous presence. This is the canvas everything else paints onto. Drag the intensity slider and the whole field swells or dims.
Stage 2 — Pose triggers
Now the body becomes a controller. We watch the joint positions and fire events on three signature poses, each computed from raw landmark geometry: both wrists above the head → a radial burst of particles; arms flung wide (wrists far apart and roughly shoulder-high) → a shockwave ring that expands outward; hands brought together (wrists close) → a pull-in that sucks particles toward your chest. Each trigger is debounced — it fires once when you strike the pose and won't fire again until you release and re-arm, so you get one burst per arms-up, not sixty. Watch the synthetic body cycle through all three; little labels flash as each one fires.
Stage 3 — Hand trails
Movement should leave a mark. We give each hand a trail — a ribbon that follows the wrist through space and fades over about a second, like a long-exposure photograph of a sparkler. Sweep your hands and you're drawing in the air; the faster you move, the brighter and wider the ribbon, because we feed hand speed into the trail's thickness and glow. Two hands, two independent ribbons. This is the "paint with your body" promise made literal — the synthetic body's sweeping arms lay down looping ribbons of light on a loop.
Stage 4 — Sound
The installation finds its voice. Every trigger now plays a note
through the Web Audio API — a soft sine tone from a pentatonic scale
(the five-note scale that can't sound wrong, which is why wind chimes and kalimbas use
it). Arms-up, arms-wide, and clap each map to their own note, and the
velocity of your motion sets the volume: a gentle gesture whispers, a
sharp one rings out. Crucially, audio is gesture-gated: browsers
forbid sound until a real user gesture, so nothing plays until you tap
enable sound, which resumes the AudioContext. Until then the
installation is silent by design — never autoplay. Once enabled, the synthetic body's
performance becomes an audiovisual one.
Stage 5 — Reactive background
The space itself should respond. We measure the body's overall motion energy — how fast all the joints are moving, summed — and feed it into a reactive field behind the figure: a radial gradient that pulses brighter and warmer the more you move, and a faint grid that flexes with the beat. Hold still and the room goes dark and calm; dance and it lights up around you. Now the installation isn't just a figure on black — it's a room that breathes with you, the single thing that turns a demo into an environment.
Stage 6 — The full installation
Everything at once. The luminous body, the three pose triggers, the twin hand trails, the pentatonic sound, and the reactive room — all live on one render loop, all driven by one body. The synthetic figure performs its full routine: it raises its arms and the screen bursts and a note rings; it sweeps and ribbons bloom; it throws its arms wide and a shockwave rolls out; it claps and everything collapses inward — and the room pulses through all of it. This is the piece. Enable sound, turn on your camera, and step into it: you are now the performer, and the installation is yours to play.
How the code works
The installation is four systems sharing one loop: a pose-trigger detector that turns joint geometry into debounced events, a particle engine (a fixed pool, no per-frame allocation) that draws the silhouette and the trails, a synth that plays a pentatonic note per trigger behind a user gesture, and a compositor that ties it all together. None of them is long.
(a) Pose-trigger detection (debounced)
A trigger is a boolean fact about the body's geometry — are both wrists above the
head? — plus an edge detector so it fires once per pose, not every
frame. We normalize all distances by the shoulder width so the thresholds are
scale-invariant: they work whether you're close to the camera or across the room. Note
that y grows downward, so "above the head" means a
smaller y than the nose.
// MediaPipe Pose indices: 0 nose · 11/12 shoulders · 15/16 wrists · 23/24 hips
function detectTriggers(lm, prev) {
const nose = lm[0], lSh = lm[11], rSh = lm[12], lW = lm[15], rW = lm[16];
const shoulderW = Math.hypot(lSh.x - rSh.x, lSh.y - rSh.y) || 0.001;
const wristGap = Math.hypot(lW.x - rW.x, lW.y - rW.y) / shoulderW; // in shoulder-widths
// y grows DOWNWARD, so "above the head" = wrist.y < nose.y
const armsUp = lW.y < nose.y && rW.y < nose.y;
// wide: wrists far apart AND roughly shoulder-height (not down at the hips)
const armsWide = wristGap > 2.6 && Math.abs(lW.y - lSh.y) < 0.5 && Math.abs(rW.y - rSh.y) < 0.5;
// clap / pull-in: wrists nearly touching
const together = wristGap < 0.7;
// EDGE detect against last frame → fire once, then must release to re-arm (debounce)
const fired = {
burst: armsUp && !prev.armsUp,
shockwave: armsWide && !prev.armsWide,
pullIn: together && !prev.together,
};
return { fired, state: { armsUp, armsWide, together } }; // save state for next frame
}
(b) The particle system + trails (pooled, additive)
The cardinal rule of a 120fps particle system: never allocate in the loop.
We pre-build a fixed pool of particle objects once, keep a write cursor, and recycle the
oldest when we run out. Spawning is just overwriting fields on a dead slot — zero garbage,
zero GC stalls. Drawing is one pass with globalCompositeOperation = 'lighter'
(additive blending) so overlapping particles sum into hot light.
const POOL = 1400;
const ps = new Array(POOL);
for (let i = 0; i < POOL; i++) ps[i] = { x:0, y:0, vx:0, vy:0, life:0, max:1, size:2, h:200 };
let cursor = 0;
// spawn = overwrite the next slot (recycles oldest). No allocation, ever.
function spawn(x, y, vx, vy, life, size, h) {
const p = ps[cursor]; cursor = (cursor + 1) % POOL;
p.x = x; p.y = y; p.vx = vx; p.vy = vy; p.life = life; p.max = life; p.size = size; p.h = h;
}
function updateAndDraw(dt) {
ctx.globalCompositeOperation = 'lighter'; // ADDITIVE: light stacks up
for (let i = 0; i < POOL; i++) {
const p = ps[i];
if (p.life <= 0) continue; // dead slot — skip
p.life -= dt;
p.x += p.vx * dt; p.y += p.vy * dt;
p.vx += pullX * dt; p.vy += pullY * dt; // pull-in trigger tugs everything
const a = Math.max(0, p.life / p.max); // fade out over its lifetime
ctx.fillStyle = `hsla(${p.h}, 90%, 65%, ${a})`;
ctx.beginPath(); ctx.arc(p.x, p.y, p.size * a, 0, 6.283); ctx.fill();
}
ctx.globalCompositeOperation = 'source-over';
}
The silhouette is just particles spawned along every bone each frame; a hand trail is particles spawned at the wrist, their size and brightness scaled by hand speed, so a fast sweep leaves a thick bright ribbon and a slow one a thin faint thread.
(c) A Web Audio note on a trigger (gesture-gated)
Browsers will not make a sound until the user has interacted with the page, so we
create the AudioContext lazily and only resume() it
from the click handler of the sound button — never on load, never automatically.
A note is a sine oscillator through a gain envelope that swells and decays; the gain's
peak is the gesture's velocity, so harder motions are louder. The scale
is pentatonic, which is why it always sounds musical.
let audio = null, soundOn = false;
const PENTA = [0, 2, 4, 7, 9]; // major pentatonic, semitone offsets
const midiToHz = (m) => 440 * Math.pow(2, (m - 69) / 12);
// MUST be called from a real user gesture (the sound-button click)
async function enableSound() {
if (!audio) audio = new (window.AudioContext || window.webkitAudioContext)();
await audio.resume(); // the gate: only opens on a gesture
soundOn = true;
}
function playNote(degree, velocity) {
if (!soundOn || !audio) return; // silent until the gesture-gate opens
const midi = 60 + PENTA[degree % 5] + 12 * Math.floor(degree / 5);
const t = audio.currentTime;
const osc = audio.createOscillator(), g = audio.createGain();
osc.type = 'sine'; osc.frequency.value = midiToHz(midi);
const peak = 0.05 + 0.25 * Math.min(1, velocity); // VELOCITY → volume
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(peak, t + 0.01); // fast attack
g.gain.exponentialRampToValueAtTime(0.0001, t + 1.1);// long decay
osc.connect(g).connect(audio.destination);
osc.start(t); osc.stop(t + 1.2);
}
(d) Compose: tie every system onto one loop
The whole installation is one function. It reads the body (synthetic or camera through
the same onLandmarks path), runs the trigger detector, fires
particles and notes on the edges, spawns the silhouette and trails, measures motion energy
for the background, and draws — in that order, every frame. Stages just gate which systems
are active, so the same loop serves all six.
function onLandmarks(lm) { // ONE path for synthetic + camera
// --- motion energy: how fast is the whole body moving? (for the reactive field) ---
energy = 0;
for (const i of [11,12,13,14,15,16,23,24,25,26]) {
if (lm[i] && prevLm[i]) energy += Math.hypot(lm[i].x - prevLm[i].x, lm[i].y - prevLm[i].y);
if (lm[i]) prevLm[i] = { x: lm[i].x, y: lm[i].y };
}
energySmooth += (energy - energySmooth) * 0.15; // smooth so the room doesn't flicker
// --- triggers (Stage 2+): edge-detected, so one event per pose ---
if (stage >= 1) {
const { fired, state } = detectTriggers(lm, trigPrev);
const vel = Math.min(1, energySmooth * 14); // gesture velocity → note volume
if (fired.burst) { burstAt(lm[0]); flash('BURST'); if (stage >= 3) playNote(4, 0.5 + vel); }
if (fired.shockwave) { shockAt(lm[0]); flash('SHOCKWAVE'); if (stage >= 3) playNote(2, 0.5 + vel); }
if (fired.pullIn) { startPull(lm); flash('PULL-IN'); if (stage >= 3) playNote(0, 0.5 + vel); }
trigPrev = state; // remember for next frame's edge test
}
spawnSilhouette(lm); // the body as light (every stage)
if (stage >= 2) spawnTrails(lm); // hand ribbons (Stage 3+)
}
(e) The same path for synthetic and camera — and the body that performs
The loop never knows whether the 33 landmarks came from a math function or a neural net
reading your webcam. On the synthetic side we don't just idle the figure — we
choreograph it: a routine timer cycles the body through arms-up, arms-wide,
clap, and sweep poses, so the installation actually performs (and fires every trigger,
plays every note) before any camera is on. The camera path lazy-imports MediaPipe and feeds
the identical onLandmarks.
const POSE_TASK =
'https://storage.googleapis.com/mediapipe-models/pose_landmarker/' +
'pose_landmarker_lite/float16/1/pose_landmarker_lite.task';
function loop(now) {
let pose;
if (usingCamera && landmarker && video.readyState >= 2) {
const res = landmarker.detectForVideo(video, now);
pose = res.landmarks?.[0] || null; // null when no body in frame
} else {
pose = performRoutine(now * 0.001); // the synthetic body DANCES its routine
}
if (pose) onLandmarks(pose); // ONE downstream path for both
render(now);
requestAnimationFrame(loop);
}
Common pitfalls
- Autoplaying audio. Creating an
AudioContexton page load and expecting it to make sound is the classic mistake — every modern browser starts itsuspendedand only a real user gesture canresume()it. That's why the sound is behind an enable sound button whose click handler does the resume. Never autoplay; gate it on the gesture, and surface that it's off until tapped. - A trigger that fires every frame. If "arms above head" is true for thirty frames, a naïve check fires thirty bursts (and thirty notes — a horrible buzz). The fix is edge detection: compare to last frame's state and fire only on the false→true transition, then require a release before it can fire again. Same hysteresis instinct as the rep counter in Episode 11.
- Allocating particles in the loop.
push()-ing new objects every frame and filtering out dead ones generates mountains of garbage; the GC then stutters your 120fps into a slideshow. Pre-allocate a fixed pool, write into a rolling cursor, and recycle the oldest. Allocation cost: zero. - The synthetic body just stands there. If your default driver only idle-sways, the finale looks dead and none of the triggers ever fire — a terrible first impression for the one episode meant to dazzle. The synthetic body must perform: script a routine that actually hits arms-up, arms-wide, and clap so the installation demonstrates itself.
- Thresholds that only work at one distance. If you test "wrists far apart" in raw normalized units, it breaks the moment you step closer or farther from the camera. Normalize every distance by shoulder width so the triggers are scale-invariant — a wingspan is a wingspan whether you fill the frame or not.
- Mirrored axis. Raising your right hand lights the left of the
screen → you forgot the
1 - xflip. Apply it to both the camera landmarks and the synthetic body so the two modes match and the selfie view feels natural. - Camera only works on localhost / HTTPS. Opening the file via
file://silently blocksgetUserMedia. The synthetic installation still performs; serve overlocalhostto step in.
Exercises
- Record the performance. Capture the canvas to a video file with
canvas.captureStream(60)fed into aMediaRecorder; wire a record button that starts/stops it and downloads a.webm. Now the installation is a tool for making clips — dance for thirty seconds and post the result. (Bonus: mix the Web Audio output in by routing through aMediaStreamDestination.) - Add a second instrument mapped to your legs. You're only listening to the arms. Track the knees and ankles (landmarks 25–28): a stomp (ankle dropping fast) could fire a low drum note, a high knee a different pitch. Now it's a full-body instrument — arms sing the melody, legs lay down the rhythm.
- A "freeze frame" pose-capture. Add a gesture (or a key) that snapshots the current landmark array and freezes a bright, persistent copy of the silhouette on screen while the live body keeps moving in front of it. Strike a pose, freeze it, then dance around your own light-sculpture — instant interactive photography.
What's next
That's a wrap on Season 2 — Body & Face. Across eight episodes you went from the bare 33-point pose and the 468-point face mesh to puppeted avatars, a rep counter, AR filters, gaze and blink triggers, particle silhouettes, and now a full audiovisual installation your whole body drives. Together with Season 1's hands, you can take any part of the human body, read it on-device in the browser, and wire it to any visual or sonic response — the entire camera → landmarks → gesture → action → feedback loop, for hands, face, and full body.
Season 3 — Frontiers pushes past the single body in a flat frame: two-hand 3D manipulation (grab and rotate objects in space), depth and WebXR hand tracking on a headset, training your own custom gestures with an in-browser teachable classifier, landmarks feeding GPU shaders and WebGPU, hands reaching into Gaussian-splat scenes (where this series shakes hands with the splatting series), and multiplayer body — streaming landmarks, not video, so two people share one space, tiny and private, over WebRTC. The body is solved; next we give it depth, memory, a teacher, and company.