Press Run, drag the length slider, or click / tap the floor to drop one needle where you tap.
Where's the maths? This is probability shaking hands with geometry and trigonometry. A needle is dropped on a floor of parallel planks, and the only question asked is whether it lands across a crack. Whether it does depends on just two random numbers: how far the needle's centre sits from the nearest crack, and what angle it makes with the cracks — and the angle enters through the sine ratio you meet in Sec 2. Every possible drop is one point in a rectangle of (angle, distance) pairs, and the drops that cross are exactly the points under a sine curve. So a probability becomes an area comparison, and that area brings in π. Run the simulation and the fraction of crossings settles down near a fixed number — the law of large numbers at work — which is why throwing needles can measure π without a single circle being drawn.
Beyond the syllabus: integrating sin θ to get 2/π is A-Math C1 (integration of sin x) — a look-ahead.
The planks have width d and the needle has length ℓ ≤ d. Drop it: its centre lands a distance y from the nearest crack, with 0 ≤ y ≤ d/2, and it makes an angle θ with the cracks, anywhere from 0 to π radians (0° to 180°). Both are equally likely across their ranges.
Half the needle reaches a vertical distance (ℓ/2) sin θ from its centre. So the needle touches a crack exactly when y < (ℓ/2) sin θ That single line of trigonometry is the whole test — the small diagram plots one dot for each drop at its own (θ, y), gold under the curve, blue above it.
Every drop is a point in a rectangle π wide and d/2 tall, so all possible drops have area πd/2. The crossing region is the area under the sine curve, which works out to ℓ. Probability is the ratio of the two areas: P(cross) = ℓ ÷ (πd/2) = 2ℓ / (πd) With a needle exactly as long as the planks are wide (ℓ = d) that is 2/π ≈ 0.6366 — about 5 crossings in every 8 drops.
Now turn it round. After N drops with C crossings, C/N estimates that probability, so π ≈ 2ℓN / (dC) The estimate on screen is computed from the crossings actually simulated — nothing is faked. Its error shrinks like 1/√N, which is brutal: 100 times as many needles buys only one more decimal place. That is what the shaded band on the convergence chart shows (a 95% range), and why Buffon's needle is a beautiful idea but a terrible way to compute π.
Try this: keep ℓ = 1.00 d, set 10 000 drops per second and run to about 100 000 drops — watch the blue curve dive into the narrowing band around π. Then reset, slide the needle down to 0.20 d and run again: crossings become rare, the dots crowd into a thin sliver under the flattened sine curve, and the same number of drops gives a much noisier estimate. Ask yourself why a longer needle is a better measuring instrument.
Controls: Run / Pause to drop needles continuously, +100 and +10 000 for instant batches, the slider for needle length, and a click or tap anywhere on the floor drops a single needle there.
Estimate vs number of drops (log scale). Gold line = π; the band is a 95% range.
Each drop as (θ, y). Gold area ÷ rectangle = 2ℓ/(πd).