---
title: "Pi · generative art"
description: "π, counted and walked. Generative art plate #38 by Theodore Vorillas, drawn live in your browser from its code."
url: "https://vorillaz.com/lab/pi"
---

![](https://vorillaz.com/_astro/pi.CUswiy_V_25tIWU.webp)

fig. #38 · rendered live in your browser from the code below

# #38 pi

π, counted and walked.

- date

  2026.10.13

- tags

  generative-art · javascript · webgl

π, twice over. Ten thousand specks are thrown at random into a cube. The ones that land inside its sphere are drawn solid and the rest barely at all, so a dark ball comes out of nothing but the count. A speck lands inside π/6 of the time, so the count is also an estimate of π, written in the corner. Through the ball, π’s own first six thousand digits walk. Each digit is one of ten directions spread evenly over a sphere, and ten walks of six hundred digits each turn back at the cube’s walls. The digits look random, so the walks look like any random walk, until you remember that every step is fixed. A few stretches are smoothed into heavy ribbons. One of them always passes the Feynman point, where six nines in a row start at the 762nd decimal place, and those six steps are marked in signal.

Play it and it turns. Every so often the specks are thrown again and the digits are dealt new directions. Switch the ground to graphite and the ball turns white.

## The digits

```javascript title="pi.js"
// Machin: π = 16·atan(1/5) − 4·atan(1/239), summed in whole numbers past the places kept
const scale = 10n ** BigInt(n + 10);
const atan = (x) => {
  let sum = 0n, term = scale / x, k = 1n, sign = 1n;
  while (term) { sum += (sign * term) / k; term /= x * x; k += 2n; sign = -sign; }
  return sum;
};
const digits = (4n * (4n * atan(5n) - atan(239n))).toString().slice(0, n);
```

## The count

```javascript title="pi.js"
// a speck anywhere in the cube lands inside its sphere π/6 of the time
for (let k = 0; k < samples; k++) {
  const p = [random(-1, 1), random(-1, 1), random(-1, 1)];
  if (length(p) < 1) inside++;
  speck(p, length(p) < 1 ? "solid" : "faint");
}
const estimate = (6 * inside) / samples;
```

## References

- [Machin-like formula](https://en.wikipedia.org/wiki/Machin-like_formula)
- [Monte Carlo method](https://en.wikipedia.org/wiki/Monte_Carlo_method)
- [Feynman point](https://en.wikipedia.org/wiki/Six_nines_in_pi)
- [Normal number](https://en.wikipedia.org/wiki/Normal_number), why π’s digits read as random
