You choose an image, wait a moment, and the same image is redrawn by two chains of rotating circles. That is the idea behind the Fourier Epicycles demo: the browser extracts the outline of the image, computes two independent Fourier series for the X and Y coordinates, and moves a pen along the resulting path.
Try the live demo now: Fourier Epicycles. No image is uploaded to a server, and every calculation runs in your browser.
Any periodic motion can be broken into a sum of simpler motions. In a Fourier series, each term is a rotating vector: a circle with a fixed radius that turns at a constant angular speed. Place several rotating vectors end to end, and the tip of the chain traces a complex path. These nested circles are called epicycles, the same idea ancient astronomers used to describe the motion of planets.
This demo differs from the classic single-chain animation because it keeps two independent series:
x(t) = a0 + Σ [ak cos(kt) + bk sin(kt)] y(t) = c0 + Σ [ck cos(kt) + dk sin(kt)]
For each axis, the amplitude and phase of every harmonic are computed separately. After sorting by amplitude, the largest circles are drawn first and the smaller details follow.
The browser first draws the image onto an offscreen canvas and scales it to a maximum of 300 pixels on the longer side. Then it runs the following pipeline:
A transparent PNG or a solid subject on a plain background gives the cleanest result. Busy photos often work, but the extracted outline may include part of the background.
A single-chain visualization usually uses one complex Fourier series to describe the whole 2D path. This demo keeps two real, independent series: one for X and one for Y. The horizontal chain at the top produces the X coordinate, and the vertical chain on the left produces the Y coordinate. A dashed guide line leaves each chain, and the intersection of the two guides is the pen position.
The split is deliberate. If X and Y are swapped, the guide intersection moves toward the edge of the canvas and the shape is drawn incorrectly. With the current layout, the vertical guide from the top chain and the horizontal guide from the side chain meet exactly at the drawing point.
The coefficients come from a discrete Fourier transform over the 1000 samples. Each harmonic stores an amplitude and a phase, and the harmonics are sorted by amplitude in descending order. The Nyquist term at the end of the spectrum uses a special coefficient so the reconstruction is exact at N=500.
The displayed error is the RMS distance between the approximated path and the original path, normalized by the original path's RMS radius. In other words, the error is measured relative to the size of the shape. For a five-point star, the measured values in the demo were:
| Harmonics | RMS error |
|---|---|
| 5 | 1.79% |
| 10 | 0.75% |
| 80 | 0.09% |
| 500 | 0.00% |
The exact numbers depend on the input shape and the contour quality, but the trend is always the same: more harmonics mean a smaller error and a closer match.
The harmonic slider runs from 1 to 500 and updates both chains immediately. The speed slider changes the angular speed, the Pause button stops the animation, and Clear trace removes the current drawing.
This demo is built for learning and experimentation, not for exact reconstruction of every photo. Keep these points in mind:
Upload a logo, a heart, or a transparent shape, and move the N slider from 5 to 200. You will see the difference between a simple ellipse and a complete outline right away. If you create something interesting, share a link in the comments below.
No Comments have been Posted.