When the homepage loads, a pen at the end of a chain of spinning circles draws the raven’s outline before the ASCII portrait appears. That animation is a Fourier series: a closed curve written as a sum of rotations. The figure below uses the same coefficients as the homepage. Change the number of circles and watch the outline sharpen.
.:=++++++*%@@@%#+:
.+#%@@@@@@@@@@@@@@@*:
.-+%@@@@@@@@@@@@-
.#@@@@@@@@@@@@.
-*#%@@@@@@@@@+
-#%@@@@@@@@@@@@#
.+%@@@@@@@@@@@@@@@@.
:*@@@@@@@@@@@@@@@@@@@+
.*@@@@@@@@@@@@@@@@@@@@@%
.+@@@@@@@@@@@@@@@@@@@@@@@%
.+%@@@@@@@@@@@@@@@@@@@@@@@@+
.+%@@@@@@@@@@@@@@@@@@@@@@@@@#
.=%@@@@@@@@@@@@@@@@@@@@@@@@@%=
=%@@@@@@@@@@@@@@@@@@@@@@@@@#=.
-%@@@@@@@@@@@@@@@@@@@@@@@@*=:
-**%@@@@@@@@@@@@@@@@@@@@@@=
:*@@@@@@@@@@@@@@@@%*=*@@%
.*@@@@@@@@@@@@@@@%%@# .*@@:
=@@@@@@@@@%@@@%*=: .-##: .+%+.
-%@@@@@@@@**@%*-. =#*: .+#=.
.*@@@@@@@%+::=: =%@#*=-#@%*+==-.
-%@@@@@%*-. . ........:...:.
%@@%#+-.Spectrum: |cₙ| sorted from largest (log scale)
A closed curve is a function of time#
Imagine tracing the raven’s outline once at a steady pace, taking one unit of time for the whole loop. At each time the pen has a position . Writing that position as a single complex number turns the drawing into one function:
Because the outline is closed, the pen returns to its starting point: . The curve is a periodic function, and periodic functions are what Fourier series describe.
One rotating arrow#
The simplest periodic motion in the complex plane is
Here is a complex number and is an integer. As runs from 0 to 1, this point moves around a circle:
- its radius is ;
- its starting angle is the angle of ;
- it completes full turns; positive and negative rotate in opposite directions;
- with it does not move. That term fixes the drawing’s centre.
Set the figure to 1 circle: the pen moves around a single circle. It is the raven’s largest term, with , and sets the overall size of the loop.
Arrows placed tip to tail#
One arrow can only draw a circle. To draw something more complex, connect several arrows: the second starts at the tip of the first, the third at the tip of the second, and so on.
In the complex plane, placing arrows tip to tail is simply addition: adding two complex numbers joins the arrows that represent them. So the end of the chain is the sum of all the arrows:
Each arrow still turns at its own constant speed, but joined together, their end traces a path far more complex than any single circle. This sum is the curve’s Fourier series. Each sets the size and starting angle of one circle.
Start with the simplest pair: add the second-largest term, , to . It turns as fast as the first arrow, but in the opposite direction. While the large arrow makes one turn, the small arrow on its tip makes one turn the other way, stretching the pen’s path into an ellipse:
Then keep adding terms in the interactive figure above:
- 3 circles: adding starts to bend the loop.
- After that: keep adding circles and watch when the beak, wing and tail appear.
Finding the size of each circle#
Now reverse the question: given the raven’s outline , how do we find each ?
The key is a simple fact: an arrow that makes a whole number of turns averages to zero over one loop. It spends equal time pointing in every direction, and those directions cancel:
Suppose we want . Multiplying the whole curve by makes every arrow turn three extra times in the opposite direction:
- the arrow’s rotation is cancelled exactly, leaving standing still;
- every other arrow now makes turns, still a non-zero whole number.
Averaging over one loop, every arrow that still turns averages to zero, and only the motionless remains. The same works for any :
In practice a computer has samples, not a continuous curve. The homepage outline was traced from the ASCII raven itself and sampled at points around the loop, the -th point at time . Replacing “the average over one loop” with “the average of these 2,048 points” turns the integral into a sum:
This is the discrete Fourier transform (DFT). 2,048 points give 2,048 coefficients, and the fast Fourier transform (FFT) computes them all efficiently. This was done once, when the animation was made; your browser only reads the results.
Which circles to keep#
Of the 2,048 possible terms, the homepage keeps 320. The choice is simple: sort by radius and keep the largest. The figure’s spectrum shows the same ordering.
The reason comes from Parseval’s theorem. If keeps only some of the terms, the average squared distance between the two curves equals the total squared size of the terms that were dropped:
Every dropped term adds its own to the error, and the terms do not interfere with each other. So for a fixed number of circles, keeping the largest ones gives the smallest average squared error. The figure’s RMS and energy readouts are computed directly from this identity.
Compared with the 320-term curve:
| Circles | Energy kept | RMS gap (share of height) |
|---|---|---|
| 1 | 86.62% | 15.4% |
| 2 | 91.56% | 12.3% |
| 3 | 95.69% | 8.8% |
| 8 | 99.15% | 3.9% |
| 32 | 99.98% | 0.58% |
| 96 | > 99.99% | 0.16% |
Energy here means over the rotating terms. The first eight circles already hold more than 99% of it. The remaining 1% is what separates a blob from a raven.
What the circles find hard#
Smooth, gently curving stretches are cheap: low frequencies describe them well. Sharp corners such as the tip of the beak, the claws and the tail are expensive. A corner changes direction suddenly, and only fast-turning arrows can follow that. With few circles every corner is rounded off; more circles make the corners sharper.
That is why the spectrum has a long, slowly shrinking tail. Among the 32 largest terms, the fastest turns 25 times per loop. Among the 96 largest, it turns 68 times. Further down the list, some kept terms turn up to 1,023 times per loop, the highest frequency 2,048 samples can represent. Every term faster than 200 turns, however, has a radius under 0.004% of the raven’s height. They hardly change the picture.
From the formula to the homepage#
The same mathematics shaped some engineering choices:
- The homepage does not compute the series. A short script,
generate_raven_path.py, adds up all 320 terms in advance and stores every point of the 2,048-sample loop as a 16-bit integer pair. The browser only decodes them. - The homepage draws at most 96 circles. Circles with a radius under 0.2 pixels cannot be seen. The outline still uses all 320 terms, so skipping tiny circles only simplifies the illustration.
- This page computes the curve in your browser because you choose the number of circles. Recomputing 2,048 points from up to 320 terms takes no more than a few hundredths of a second.
How this website is built describes the site around these pieces.
Circles on circles#
Drawing with circles on circles is an old idea. Ancient astronomers described planetary motion with epicycles: a small circle whose centre moves around a larger one. A Fourier series is the same construction with as many circles as needed. Given enough of them, it can follow almost any closed path. That flexibility explains both why epicycles could match observations well and why a good fit alone does not show that a model explains the motion.
The raven on the homepage is not a planet, but the principle is the same: 320 circles, each turning at its own constant speed, are enough to draw it.