Fibonacci sequence and the golden ratio

The golden ratio also shows up in nature (sunflower seeds, pine cones) - this demo has two views: the sunflower pattern places each seed by rotating it by the golden angle, while the golden spiral is built from quarter-circle arcs inscribed in squares with Fibonacci side lengths. Both grow live in your browser, while the high-resolution version is drawn on the server with PHP GD and available for download.

Watch it grow

The sunflower grows seed by seed on the canvas: every new seed is placed rotated by exactly the golden angle (≈137.508°) from the previous one, at a distance proportional to √n from the center. The drawing uses the same formula and gradient as the server, only here the browser paints it, live.

Mode
Seed count
Gradient
SEEDS: 526 / 600
ANGLE: 137.508°
Golden angle: no gaps
SunflowerVogel formula · r = c·√n
The seeds are growing...
Angle between two seeds: 137.508°
Drag the slider: even a tenth of a degree off creates spokes and gaps, only the golden angle fills the disc evenly. (computed in the browser only, the server always uses the golden angle)
Downloaded image size
Download server render
The downloadable PNG is rendered on the server with PHP GD at high resolution. The mode, count and gradient above apply, the size is chosen here.

What is the Fibonacci sequence?

Every term in the Fibonacci sequence is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55... The sequence was introduced to Europe by the 13th-century Italian mathematician Leonardo Fibonacci, though Indian mathematicians (Pingala, Virahanka) had described it centuries earlier.

As you move further along the sequence, the ratio of two consecutive terms gets closer and closer to the golden ratio (φ ≈ 1.618). It has been considered pleasing since antiquity, but claims that famous buildings and artworks were deliberately built on it are mostly read into them after the fact (see the Myth card below).

The golden spiral view above draws exactly this proportion: each new square's side is the sum of the two previous squares' sides, and the inscribed quarter-circle arcs trace out a continuous spiral.

The sunflower view illustrates a real botanical phenomenon called phyllotaxis: a sunflower's seeds (and the leaves or scales of many other plants) grow rotated relative to each other by the golden angle (≈137.5°) - the angle that produces the tightest, least wasteful packing, exactly as the pattern above shows.

The golden ratio and Fibonacci numbers really do show up in nature and mathematics, but not everywhere popular articles claim. Every drawing on these cards is generated in your browser, there are no photos. The card with the "Myth" badge shows what measurements do not support.

Sunflower head

The seeds form two families of spirals turning in opposite directions, and the spiral counts are two neighbouring Fibonacci numbers. Pick which family to color.

typically 34 and 55 spirals

Pine cone and pineapple

The scales of a pine cone typically form 8 and 13 spirals. On the hexagonal fields of a pineapple, spirals show in three directions: 8, 13 and 21. A strong tendency, not an exceptionless law.

cone 8 and 13, pineapple 8, 13, 21

Petal counts

Many flowers have a Fibonacci number of petals: lily 3, buttercup 5, delphinium 8, ragwort 13, aster 21. This is a strong tendency, not a law: it can differ between varieties and individual flowers.

3, 5, 8, 13, 21 petals

Leaf arrangement on a stem

5/13 turn = 138.5°

Two consecutive leaves around the stem are turned by a fraction of the circle: 1/2, 1/3, 2/5, 3/8, 5/13 ... These are ratios of Fibonacci numbers and tend to 1/φ² ≈ 0.382 of a turn, the golden angle (137.5°).

limit: 0.382 turn = 137.5°

Romanesco broccoli

The pointed towers of the head line up in spirals, and each tower is itself made of smaller towers of the same shape: self-similarity. The spiral counts are typically Fibonacci numbers here too. The drawing is a simplified computed model.

golden-angle layout, 2 levels

Family tree of a drone

● drone● female

Drones develop from unfertilized eggs, so they have one parent (the mother), while females have two. Going back, the number of ancestors per generation is a Fibonacci number. (The drawing ignores inbreeding.)

1, 1, 2, 3, 5, 8 ancestors

Fibonacci's rabbits

● adult pair● newborn pair
Month 7: 13 pairs

Liber Abaci (1202): a newborn pair of rabbits matures in a month, then bears a new pair every month, and none ever dies. The number of pairs by month: 1, 1, 2, 3, 5, 8 ... An idealized puzzle, not real animal breeding.

Pascal's triangle

11112113311464115101051161520156117213535217118285670562881
1 + 5 + 6 + 1 = 13 = F(7)

The numbers on the "shallow" diagonals of the triangle (where row plus column is constant) add up to the Fibonacci numbers. Pick a diagonal.

Pentagon and pentagram

side 1diagonal 1.618

In a regular pentagon the ratio of the diagonal to the side is exactly φ = (1 + √5) / 2. The crossing points also divide the pentagram lines in the golden ratio.

diagonal : side = φ ≈ 1.618

The ratios converge

φ = 1.6180F(15)/F(14) = 1.618037

The ratio of two neighbouring Fibonacci numbers approaches the golden ratio alternately from below and above: φ = 1.6180339887... The values are exact, computed from integers.

F(n+1) / F(n) → φ

Nautilus: not a golden spiral

Myth
● golden spiral● nautilus

A nautilus shell is a logarithmic spiral, but not the golden spiral: it widens about threefold per turn, while the golden spiral widens by φ⁴ ≈ 6.85 per turn. The golden ratio in the Parthenon, the Mona Lisa or the "ideal face" is not established either: the measurements can be fitted selectively.

nautilus ≈ 3x, golden spiral ≈ 6.85x per turn

"Real PHP runs": 4 methods, real measured time

All 4 PHP functions below ACTUALLY run on the server, freshly on every click - the time is not simulated, it is measured with PHP's own nanosecond-precision clock (hrtime).

n = 20
Naive recursion
Dynamic programming
Binet's closed formula
Fast matrix exponentiation
N: -
The raceLog scale · real server measurement
The bar length is logarithmic: every gridline is 10x the time. On a linear scale the fast methods would be invisible.
Code of the 4 methods

The textbook solution: fib(n) = fib(n-1) + fib(n-2), with no speedup at all. It recomputes the same subresults over and over, so it slows down exponentially as n grows.

function naiveRecursive(int $n): int
{
    if ($n < 2) {
        return $n;
    }
    return naiveRecursive($n - 1) + naiveRecursive($n - 2);
}

Why is naive recursion exponential?

Every call starts two more and recomputes the same subresults again and again. The colors mark the value of k: many nodes of the same color are wasted, repeated work.

CALLS: 21,891
from the formula: 2·F(n+1) - 1
F(2) recomputed 4,181x
Call tree of fib(20)Deep subtrees collapsed into triangles