← All demo levels

Level 4 · The whole computer

Ten things that leave the page

Everything in Levels 1–3 happened inside the browser window. These reach outside it — to the graphics card, the camera, the microphone, the motion sensors, and every processor core you own.

What changed this time Until now, a web page was a picture you could draw on. From here it's a program with access to the machine — and to the room you're sitting in.

Some of these will ask permission. That's the point, and it's worth noticing how it feels: you decide, every time, and saying no just means that one demo doesn't run. Nothing else breaks.
1

Real 3D, drawn by maths

What it takes to build

Hardest yetA weekRuns on the graphics card~60 lines

Level 3's maze faked 3D. This is the real thing — and there's still no 3D model anywhere. There are no shapes, no vertices, no mesh. The scene is described as a formula.

How it works: write one function that answers a single question: "from this point in space, how far is the nearest surface?" For a sphere that's the distance to its centre minus its radius. One line.

Now, for every pixel, fire a ray and ask that question. If the answer is "4 units away", you can safely jump 4 units forward — nothing can be in the way. Ask again. Jump again. Within about sixty jumps you've either hit something or left the scene. That's raymarching.

The two blobs melt into each other because of one extra line that blends the two distances smoothly. Try doing that with normal 3D models.

And the real jump: this code doesn't run on your processor. It runs on your graphics card, which does all the pixels at the same time instead of one after another. That's why it's smooth.

What to ask for:

WebGL raymarching fragment shader on a fullscreen triangle. Signed distance functions for two spheres and a ground plane, combined with a smooth minimum so they melt together. March up to 64 steps per ray, get the surface normal by sampling the distance field either side on each axis, and shade with one directional light plus distance fog. Animate the spheres with a time uniform.
2

A hundred thousand dots

What it takes to build

Harder2–3 days2,000× Level 1~45 lines

Remember Level 1's generative art? Forty-six dots. Your processor moved each one, one at a time, sixty times a second, and that was enough to be interesting.

This is one hundred thousand, and it's using less of your battery.

How it works: the trick is that nothing is ever stored or updated. Each dot has one number — a seed. Its position is calculated from that seed and the current time, fresh, every frame. No memory, no list to walk through, no updating.

And because your graphics card has thousands of small processors, it works out all 100,000 positions simultaneously. Your main processor's entire job each frame is to say "draw them" and go back to sleep.

That's the whole lesson of the GPU: not faster, but many at once.

What to ask for:

WebGL point rendering of 100,000 particles where the only attribute is a seed float. Compute each position in the vertex shader from the seed and a time uniform — an orbit with a per-particle radius, speed and wobble — so nothing is stored or updated on the CPU. Additive blending, small point size, low alpha.
3

Your camera, rewritten live

Nothing leaves your device. There is no server here — this page can't send your picture anywhere even if it wanted to.

What it takes to build

MediumA dayAsks permission~50 lines

How it works: ask the browser for the camera. It asks you. If you agree, you get a live video, which you can draw onto a canvas — and once it's on a canvas, it's just the list of numbers from Level 2's filter demo. Now it's 30 lists a second.

Edges: compare each pixel to the one on its right and below. Big difference means something changed there — an edge. Small difference means flat colour.

Motion: keep the previous frame and subtract it from this one. Anything that didn't move cancels out; only movement survives. That's genuinely how a lot of security cameras decide when to start recording.

This one needed fixing, and the reason is a good lesson The first version did exactly what the paragraph above describes — and looked completely broken. Measured: sitting still lit 0.4% of the screen, and waving your arms about lit 8.8%. So over 91% was black at all times, and you couldn't tell it was working at all.

Two changes fixed it. Keep the video visible but dimmed underneath, so you always see yourself. And give motion a trail that fades over about half a second, so a quick wave leaves a glowing wake instead of a single invisible frame.

The algorithm never changed. It was right the whole time. What was wrong was the presentation — and "technically correct, looks broken" is indistinguishable from broken to whoever's using it.

Worth understanding properly: this can't work without you saying yes, and you can take that back any time. Every powerful thing a page can do is gated like this. Knowing which questions get asked is how you notice when something asks for more than it should.

What to ask for:

getUserMedia camera into a video element, drawn to canvas each frame. Add an edge filter comparing each pixel to its right and lower neighbour, and a motion filter that subtracts the previous frame. Handle the user refusing permission with a clear message rather than an error.
4

Sing a note

Stays on your device. Nothing is recorded or sent.

What it takes to build

Harder2–3 daysAsks permission~45 lines

Sing, hum, or whistle. It names the note and shows how sharp or flat you are.

How it works: the microphone gives you 2,048 numbers describing the wave. A note is a wave that repeats. So: slide a copy of the wave over itself and find the shift where it lines up with itself best. That shift is the length of one cycle — and pitch is just how many cycles fit in a second.

That's called autocorrelation, and it's a lovely piece of thinking: to find something that repeats, compare it to a delayed version of itself.

The trap that breaks every naive version A wave that repeats every 100 samples also lines up with itself at 200, 300 and 400 samples. So if you simply take the strongest match, you get a note one or two octaves too low.

My first attempt did exactly that. Measured against known tones: 220Hz came out as 55Hz. 261Hz came out as 52Hz. 880Hz came out as 440Hz. Wrong by up to 80%, and confidently so.

The fix is one line: before hunting for the best match, walk past the first downhill slope. That skips the false peak sitting at zero shift and lands on the real cycle. After the fix, all eleven test notes came out within 0.8 cents — well under what anyone can hear.

Also worth knowing: the first version checked every possible shift, which worked out to 89 million sums a second and pinned the processor for nothing. Capping the search at the lowest note anyone would sing, and only running it 20 times a second instead of 60, made it about 40× cheaper with no loss of responsiveness.

Then to turn a frequency into a note name: each semitone is a fixed multiplication, so the maths is one logarithm. The needle shows cents — hundredths of a semitone — which is exactly what a guitar tuner does.

What to ask for:

Microphone pitch detection with Web Audio. Get float time domain data, run autocorrelation over offsets from 32 to 1000 samples, pick the offset with the highest correlation, and turn sampleRate/offset into a frequency. Ignore it when the signal is too quiet. Convert to note name and cents off, and show a tuner needle.
5

Talk to the page

Press the button and say something.

Chrome or Edge only. The bar shows the microphone level — if it moves, the mic is working.

What it takes to build

EasyAn hourChrome only~20 lines

How it works: honestly? You ask, and the browser does it. Speech recognition is built in. Twenty lines and your page listens.

The interesting part is the grey text. As you speak you'll see a faint guess that keeps changing, then it firms up and goes solid. That's the recogniser revising its mind as more sound arrives — "recognise speech" and "wreck a nice beach" sound identical until context arrives.

The honest caveat: this one only works in Chrome and Edge, and unlike the camera and microphone demos above, some browsers send the audio to a server to do the recognition. That's a real difference worth knowing about — "it works" and "it works privately" aren't the same claim.

This is also the exact feature behind the voice dictation in Section 2. Same idea, wired into your editor.

This one needed fixing too — and it's the same lesson a third time The first version started listening and, if no words were recognised, did nothing at all. No error, no message, no sign of life. Instrumenting it showed the recogniser was genuinely starting, hearing sound, and ending with neither a result nor an error — a case I simply hadn't handled. So it silently restarted forever while the box sat empty.

Three fixes: a live microphone level bar so you can see it hearing you before any words appear, a message after six seconds if nothing has been recognised, and a guard against restart loops so a persistent failure can't spin the processor.

The pattern across all three of these demos: the camera motion filter, the pitch detector and this one all failed differently, but all looked the same from outside — nothing happening. Most of the work in making something feel reliable isn't the algorithm. It's saying what's going on when the algorithm has nothing to show.

If it doesn't work for you

  • Use Chrome or Edge. Safari and Firefox don't support this properly.
  • Watch the bar. If it moves when you talk, your microphone is fine and it's the recogniser struggling — speak slower and a bit louder.
  • If the bar stays still, your browser is listening to the wrong microphone. Check the padlock icon in the address bar.

What to ask for:

Web Speech API recognition with continuous and interim results. Show interim text faded and final text solid, restart automatically if it stops, and detect when the API is missing so unsupported browsers get a clear message instead of a crash.
6

Tilt your phone

Best on a phone. On a laptop there's usually nothing to read.

What it takes to build

EasyA few hoursPhones only~25 lines

How it works: your phone contains a tiny weight on springs, so small it's etched into silicon. When the phone tilts, the weight shifts, and the chip measures by how much. The browser hands you that as two angles, sixty times a second.

Feed those angles in as gravity — the direction the ball should accelerate — and it rolls downhill. Add a bounce at the walls and slight friction so it settles.

A detail worth knowing: on iPhones this only works if you tap a button first. A page can't just start reading your motion sensors — Apple required a deliberate tap after people worked out that motion data alone can be enough to guess what you're typing.

What to ask for:

Device orientation ball-in-a-box. Use beta and gamma as acceleration, integrate into velocity with damping, bounce off the edges. Call DeviceOrientationEvent.requestPermission inside the click handler for iOS, and show a clear message on devices that have no motion sensor.
7

Using every core you own

One core — the normal way
Every core at once

counts every prime up to 260,000 — twice

What it takes to build

MediumA dayReal parallelism~50 lines

How it works: your computer has several processors. By default, a web page uses exactly one of them — so your laptop can be 80% idle while a page struggles.

A Web Worker is a second piece of JavaScript running genuinely at the same time, on a different core. Split the job into 24 chunks, hand them out to however many cores you have, collect the answers as they come back.

Watch both bars. Same work, same answer, several times less waiting.

The catch, and it's a real one: workers can't touch the page. No changing text, no reading elements — they can only send messages back. That restriction is deliberate: two cores editing the same page at once would be a catastrophe. So workers get the muscle and none of the hands.

What to ask for:

Compare single-threaded work against Web Workers. Count primes in a range, split into 24 chunks. Run once on the main thread yielding with setTimeout so the progress bar paints, then again across navigator.hardwareConcurrency workers created from a Blob URL. Show both times and the speedup.
8

Evolution solving a problem

What it takes to build

Harder2–3 daysNo maths required~55 lines

Press Evolve and wait. 120 dots try to get from the corner to the red circle, past a wall. At first they all fail, stupidly — most fly straight off the edge. By about generation 10 roughly half are arriving, and it keeps climbing from there.

Nobody wrote any steering code. Each dot carries a list of 90 random shoves — that's its entire brain, and it can't see the wall or the target.

Then, each generation: let them all fly, score each by how close it finished, pick parents with a bias toward the better ones, and make children by mixing two parents' lists with a 1.5% chance of a random change. Repeat.

That's evolution: vary, select, repeat. No intelligence anywhere. Solutions appear because bad ones have fewer children.

Worth sitting with: this is a genuinely different way to get an answer. You don't tell it how to solve the problem — you only tell it how to score an attempt, then let bad attempts die out.

What to ask for:

Genetic algorithm on canvas: 120 individuals, each a list of 90 random acceleration vectors. Simulate all of them, score by final distance to target with a bonus for arriving and a penalty for crashing, then breed a new generation using fitness-proportional selection, crossover and a small mutation rate. Draw all paths faintly and the best one boldly.
9

A world that doesn't exist yet

What it takes to build

MediumA dayInfinite, stored nowhere~40 lines

How it works: this landscape goes on forever and none of it is saved. There's no map. The hills a minute ahead don't exist yet, and the ones behind have already stopped existing.

Each hill's height is a function of its position. Scatter random heights at whole-number positions, then smoothly blend between them — that's noise. Rough, but recognisably landscape-ish.

Then the trick that makes it look real: add several layers of that noise together, each half the size and half the height of the last. Big rolling shapes from the first layer, medium bumps from the next, fine detail from the last. That's how real mountains are — big shapes with smaller shapes on them.

This is how Minecraft makes worlds, and why two people typing the same seed get the same planet. The world isn't stored. It's recalculated.

What to ask for:

Infinite scrolling parallax landscape on canvas using value noise: hash-based random values at integer positions, smoothstep interpolation between them, and five octaves summed at halving amplitude and doubling frequency. Three layers at different scales and speeds. Nothing stored between frames except the scroll position.
10

Teach it your handwriting

?

draw a number, then press the button that says what it was

What it takes to build

MediumA dayLearns from you~50 lines

It starts knowing nothing. Draw a 3, press the 3 button. Do that a few times for a few digits. Then draw one and don't tell it — watch it guess.

How it works: shrink whatever you drew from 140×140 pixels down to an 8×8 grid of brightnesses — 64 numbers. That deliberate blurring is what lets it cope with your 3 never being drawn quite the same way twice.

To guess: compare those 64 numbers against every example it's been shown, and report the label of the closest one. That's it. It's called nearest neighbour, and it doesn't train, doesn't have weights, and does no maths beyond subtraction.

Compare it to Level 3's neural network. That one learned slowly and ended up with numbers that mean something. This one learns instantly and just memorises. Both are machine learning. Neither is cleverer — they trade off differently, and knowing which trade you want is the actual skill.

Show it three examples and it's unreliable. Show it twenty and it's uncanny. That's the data lesson, and you can feel it happen in about two minutes.

What to ask for:

Handwritten digit recogniser with no training: draw on a canvas, downsample to an 8x8 grid of average brightness, store that with a label the user supplies, and classify new drawings by nearest neighbour using Euclidean distance. Let me wipe its memory.

What Level 4 was really about

Every level so far added something. This one added the rest of the machine.

LevelWhat you were using
1 · EffectsThe screen
2 · IdeasThe screen, plus a rule repeated fast
3 · SystemsOne processor core, running a whole program
4 · The whole computerThe graphics card, every core, the camera, the microphone, the motion sensors
The one to actually sit with The permission prompts. Three demos on this page asked before doing anything, and saying no just meant that demo didn't run.

That's the deal the whole web runs on. A page can do remarkable things — see you, hear you, know how you're holding your phone — but only after you agree, and only for as long as you agree.

Now that you've built things on this side of the prompt, you'll read those requests differently forever. A drawing app asking for your microphone should make you suspicious, because you now know it has no reason to need it.

Things to try

  1. Add a shape with one line. In the 3D demo, add another sphere(...) to the scene function and min it in. A new object appears, correctly lit, correctly shadowed, melting into the others. No model, no mesh.
  2. Break the GPU's back. Change 100,000 particles to 1,000,000. On most machines it keeps going. Then try running that loop on the processor and watch the page die.
  3. Count the cores. Type navigator.hardwareConcurrency into your browser console. That's how many cores your page was ignoring until demo 7.
  4. Flatten the fitness. In the evolve demo, change Math.pow(1/(d+1), 4) to just 1/(d+1). It stops working almost entirely — because the best dot becomes only 1.8× likelier to breed than the worst, and selection can't climb a slope that gentle. This is a real bug I hit building this page.
  5. Cripple it the other way. Set the mutation rate to 0. It stalls — with no new variation, selection has nothing left to choose between. Then set it to 0.5 and it never settles. Life needs both, and the useful range is narrow.
  6. Starve the recogniser, then feed it. Teach it exactly one example of each digit and test it. Then give it twenty each. Same code, completely different machine. That is what "more data" means.