This simulation arranges the integers from 1 to N along a winding path and highlights the primes, exposing structure invisible in a plain list. A Sieve of Eratosthenes flags every prime up to N, then each number is mapped to a screen position: a square grid for the Ulam spiral, polar coordinates for the Sacks spiral and the golden angle for the Fibonacci sunflower. Primes are drawn in colour while composites stay dark.
Choose the spiral type, set N from 100 to 20,000, adjust the Ulam cell size and pick a colour scheme (blue, gold, rainbow by digit sum, or density heat map). You can pan by dragging, zoom by scrolling, redraw, and export the view as a PNG. Beyond its visual appeal, the Ulam spiral matters because its diagonal streaks correspond to prime-rich quadratic polynomials, a real open question in number theory.
What is a number spiral?
A number spiral plots the natural numbers along a continuous winding path and marks which ones are prime. Because primes are highlighted against dark composites, alignments and clusters become visible that you would never spot in an ordinary numbered list.
What is the Ulam spiral?
The Ulam spiral writes the integers on a square grid, starting at the centre and winding outward ring by ring. When the primes are coloured in, they tend to line up along surprising diagonal stripes. Stanislaw Ulam noticed this in 1963 while doodling during a dull lecture.
How does this simulation find the primes?
It uses a Sieve of Eratosthenes. Starting from 2, it repeatedly marks every multiple of each prime as composite, so after one pass every number up to N is flagged as prime or not. This is fast enough to handle the full 20,000 numbers instantly.
The Sacks spiral places each integer n at radius r = sqrt(n) and angle 2*pi*sqrt(n) in polar coordinates. A key effect is that the perfect squares all fall on a single ray (the positive x-axis), and the prime patterns appear as curves rather than the straight diagonals of the Ulam grid.
It places each number at radius sqrt(n) and angle n times the golden angle, about 137.508 degrees. This is the same rule real sunflower seed heads follow, producing the tightest, gap-free packing. Here the primes are simply coloured to overlay number theory on a natural phyllotaxis pattern.
The golden angle equals 360 degrees times (1 minus 1/phi), where phi is the golden ratio, giving roughly 137.508 degrees. Because phi is the most irrational number, successive seeds never align into spokes, which is why it yields the most even seed packing seen in sunflowers and pine cones.
Diagonals in the Ulam spiral correspond to quadratic polynomials of the form 4n squared plus bn plus c. Some such polynomials are unusually rich in primes, so their values trace bright lines. The most famous is Euler's n squared plus n plus 41, which is prime for every n from 0 to 39.
Spiral type switches between Ulam, Sacks, Fibonacci and the composite map. Numbers (N) sets how many integers are plotted, from 100 to 20,000. Cell size scales each Ulam square in pixels. The colour scheme recolours primes by a fixed hue, by digit sum or by factor density, and Redraw or Save PNG re-renders or exports the view.
That mode hides the primes and instead colours each composite by omega, its number of prime factors counted with multiplicity. Numbers with two factors get one hue, three factors another, and so on, so you can see the texture of how composites are built rather than where the primes sit.
It is real and statistically significant, not an artefact of the drawing. The pattern reflects genuine biases in which quadratic forms produce primes, and remains only partly explained. The Hardy and Littlewood conjecture F gives predictions for prime density along such lines, but no complete proof exists.
Discover hidden patterns in prime numbers! The Ulam spiral reveals mysterious diagonal lines of primes. Sacks spiral and Fibonacci sunflower show how primes connect to nature's geometry.
Numbers are placed in spiral patterns. Prime numbers are highlighted, revealing unexpected structures — diagonal lines in Ulam's spiral correspond to prime-generating quadratic polynomials.
Switch between Ulam, Sacks and Fibonacci spirals. Pan and zoom. Toggle composite highlighting. Export as PNG.
Ulam discovered his spiral doodling during a boring meeting in 1963. The visible diagonals correspond to polynomials like n² + n + 41, which Euler noted produces primes for n = 0 to 39.