← henderhead

Continued fraction Fourier

after a demo by Matt Henderson
what to draw
the series
this number

What this is

On 9 September 2026 Matt Henderson posted a picture: drawing a picture from the continued fraction of a number — the continued fraction terms drive a Fourier series. The idea, the formula and the choice of numbers are his. This page is an independent rebuild of the demo so you can turn the knobs; the original post, with his own renders, is here, and it is worth seeing first.

The formula

z(t) = Σk ei qk t / qkα   t ∈ [0, 2π)

Write a number as a continued fraction, x = [a₀; a₁, a₂, …]. Truncating it after each term gives the convergents pk/qk — the best rational approximations to x. The denominators qk are the only thing that draws. Each one contributes a circle of radius qk−α going round qk times per turn; stack them tip to tail and the pen at the end traces the picture. α = 1 is Matt's first image, α = ½ his second — "introducing a sqrt lifts more detail", because the amplitudes then fall away far more slowly.

q₀ = 1 for every number, and a₀ appears nowhere else, so only the fractional part draws: π and 22/7 and −0.858… all start from the same unit circle. 22/7 = [3; 7] is that circle plus a seventh-size one going round seven times, and nothing more, because a rational's expansion stops. 355/113 = [3; 7, 16] adds 113 ripples on top of the same seven lobes — which is a picture of why 355/113 is such a famously good approximation to π.

Rough and smooth

In the thread, lisyarus noticed that the transcendental numbers come out much smoother than the low-degree algebraic ones, and Matt agreed the roughness measures how well the number is approximated by its own convergents. You can see the mechanism directly here. Amplitude qk−α falls as fast as qk grows, so a number whose qk climb slowly keeps large circles at high frequencies, and keeps wiggling. The golden ratio is [1; 1, 1, 1, …] — every term the smallest it can be, so its qk are the Fibonacci numbers, the slowest growth any irrational can have. φ is the roughest picture on this page, and that is not a coincidence: it is the same fact as φ being the hardest number to approximate by rationals.

The opposite end is more startling. Liouville's constant has a partial quotient of 999 999 999 999; Champernowne's has 149 083. One enormous term sends qk out of sight in a single step, every circle after it is smaller than a pixel, and the picture simply stops developing. Try them.

How it computes

The expansion is done exactly, not in floating point, by a small Rust engine compiled to WebAssembly (engine/ here, 52 KB, no imports and no bindgen). Fractions go through Euclid in 128-bit integers. Quadratic irrationals — √2, √3, φ, and anything you type as (a+sqrt(n))/c — take a separate exact route whose terms are eventually periodic and therefore never run out. Everything else is a decimal, given here to 40 significant figures and expanded exactly as the rational it literally is; the panel says how far up the term list those digits can vouch for, which is well past anything the screen can show. The sampler is what actually needs the speed: a curve with a frequency of 15 000 in it needs a few hundred thousand samples before the fine structure stops being a lie about the number.

Credit, and a request

This is a fan page. The mathematics and the demo are Matt Henderson's (matthen.com, @matthen.com); the code here is ours and none of his images or videos are copied onto this site. If he would rather this did not exist, or wants anything about it changed, that decision is his and we will act on it — see the note on the front page.