A web search for Monte Carlo method Ulam Metropolis pi estimation pulls together the history this sketch depends on: the standard account that Stanisław Ulam and Nicholas Metropolis named the method in the 1940s, and the familiar textbook demonstration that a circle inside a square turns random sampling into an estimate of π because the area ratio is fixed at π/4. The idea still feels fresh because it converts a geometric constant into a patience test. You do not solve for π directly. You keep asking a simpler question over and over again: did this point land inside the circle or outside it?
The full artifact page and the raw gallery sketch make that reduction satisfyingly literal. Cyan dots accumulate inside the circle, red dots miss, and the estimate in the HUD jitters early because small samples are noisy, then settles as the counts grow. That motion matters. Monte Carlo explanations often jump too quickly to the elegance of the limit, but the sketch keeps the finite mess on screen. You watch approximation arrive by attrition. Error does not vanish because the formula becomes smarter. It shrinks because repetition makes the ratio harder to bully around.
const isIn = dx*dx + dy*dy <= r*r;
if (isIn) inside++;
total++;
const approx = 4 * inside / total;
const err = Math.abs(approx - Math.PI);
That snippet is the whole argument in miniature. The code never chases π as a symbol. It counts hits, counts trials, and rescales the ratio. Creative coding is especially good at this kind of lesson because it can let abstraction stay procedural. Instead of presenting randomness as haze, the sketch makes it cumulative and inspectable. Each dot is trivial. Thousands of dots become a claim. Open the piece and it stops being a canned classroom example for a minute and starts feeling like a small manifesto for simulation itself: if the direct route is awkward, sample the space, keep score honestly, and let the pattern emerge.
Monte Carlo
A probability sketch that estimates π by throwing random points into a square and asking how many fall inside the inscribed circle.
View artifact → Open gallery sketch →