← 📐 Mathematics

🔢 Number Spirals

Spiral type
Colour scheme
Max N
Primes found
Prime density
Prime
Composite
N=1 (origin)
Scroll to zoom · Click & drag to pan

About Number Spirals

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.

Frequently Asked Questions

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.

What does the Sacks spiral do differently?

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.

What is the Fibonacci sunflower mode?

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.

What is the golden angle and why 137.5 degrees?

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.

Why do the diagonal lines appear in the Ulam spiral?

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.

What do the controls actually change?

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.

What does the composite highlights mode show?

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.

Is the clustering of primes along diagonals real or coincidence?

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.

🔢 Number Spirals — Ulam & Sacks

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.

🔬 What It Demonstrates

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.

🎮 How to Use

Switch between Ulam, Sacks and Fibonacci spirals. Pan and zoom. Toggle composite highlighting. Export as PNG.

💡 Did You Know?

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.

🔢 Number Spirals

About this simulation

Number spirals arrange the integers along a winding path and highlight the primes, exposing structure that is invisible in an ordinary list of numbers. The most famous is the Ulam spiral, where primes mysteriously cluster along diagonal lines. The same data plotted as a Sacks spiral or a Fibonacci sunflower links prime distribution to the polar geometry seen in plants and seed heads — a vivid bridge between number theory and the patterns of nature.

How it works

Key equations

Sacks: r = sqrt(n), angle = 2*pi*sqrt(n) — n is the integer, r the radius, so perfect squares line up on the positive x-axis.

Sunflower: angle = n * 137.508 deg — the golden angle, derived from the golden ratio phi, gives the tightest seed packing.

Controls

Did you know?

Stanisław Ulam discovered his spiral in 1963 while doodling during a dull lecture. Its brightest diagonals trace Euler's polynomial n² + n + 41, which yields a prime for every n from 0 to 39 — a record that still has no full explanation.