Circles All The Way Down
Draw any closed shape and it turns out to be a stack of rotating circles. Provably, and with a receipt.
What it is
Draw a closed shape with the pointer. It gets resampled to 256 evenly spaced points, transformed, and redrawn as a chain of circles rotating at whole-number speeds, each one’s centre riding on the rim of the last. The tip of the chain traces your shape.
Add and remove circles and watch the trace get sloppier or sharper.
How it works
This is the discrete Fourier transform read geometrically. Each coefficient is literally a circle: magnitude is the radius, argument is the starting angle, and the index is how many turns it makes per lap. Negative frequencies turn the other way, which is why some circles run backwards.
Two details make it work in practice. The path is resampled to even arc length first, because if you draw slowly in one corner and quickly in another the transform would otherwise spend its coefficients describing your hand speed rather than your shape. And the circles are sorted by radius before drawing, so adding “more circles” adds the ones that matter most.
What surprised me
I wrote two tests before touching any drawing code, and one of them is the best test I’ve written in this whole series.
A circle traced once, at constant speed, is one rotating circle. So its transform should have exactly one non-zero coefficient, of radius 1, at frequency ±1, and everything else should be zero to floating-point precision.
That single assertion pins down the normalisation, the sign convention, the frequency mapping and the phase convention all at once. Get any of them wrong and it fails.
The second is Parseval’s theorem. Total energy is the same in both domains, so the mean squared magnitude of the path has to equal the sum of squared coefficient magnitudes. That’s an audit the transform performs on itself, it needs no reference implementation, and it holds for any input at all.
Between them those two tests would catch essentially any mistake I could make here, and I had them passing before there was anything to look at. That’s a much better position than the one I’ve been in on several of these days, where the visual was the first thing to tell me something was wrong.
What I would do next
Draw the coefficient magnitudes as a spectrum, and watch which frequencies a sharp corner actually needs.