Throwing darts at a drawing

How big is a blob? For a circle there's a formula, but for a doodle there isn't. You can still measure it by throwing darts. Throw them at random over the canvas and count how many land on ink. The share that hits is roughly the share of the canvas the blob covers. This is a Monte Carlo estimate: it works for any shape, and the more darts you throw, the closer it gets.

Throw some darts

The canvas starts with a disc. Paint over it, erase bits of it, or clear it and draw your own shape. Every stroke rethrows the same darts at the new drawing.

Of 500 darts, hit the ink. So the shape covers about of the canvas, give or take points. Counting every one of its 90,000 pixels, it covers .

The darts on the right land in the same places as long as the seed stays the same, so you can watch single darts turn orange as you paint over them.

How fast it settles

A few darts give a rough answer, and every extra dart refines it. This chart follows the estimate as the darts come in, one at a time, against the exact share (the dashed line).

Throwing four times as many darts only halves the error. The "give or take" above is two standard errors, 2√(p(1 − p)/n), so about 19 times out of 20 the estimate lands that close to the truth. With darts, that's points.

A dart's estimate of π

The starting disc touches all four sides of its square canvas, so it covers π/4 of it. That makes four times the hit rate an estimate of π: right now , if the disc is still there. Click Clear in the toolbar to bring it back, since it's the src image.

Things to try

How it's built