Visualizations
161 / 500

161 · Math

Fourier Epicycles

A chain of spinning circles traces any drawing you give it.

A discrete Fourier transform turns a closed path into a list of rotating vectors, each with its own frequency, length and starting angle. Laid tip to tail and sorted largest first, those circles redraw the original path as they spin. Fewer circles give a smooth sketch; more add detail.

Try it. Draw a shape with the pointer and the circles will learn it. Arrow keys halve or double the number of circles.

  • Discrete Fourier transform
  • Complex numbers
  • Path animation

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a Fourier epicycles drawing machine with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Use a warm cream paper background with dark ink lines.
- Make a closed path of about 300 points. Start with a heart: x = 16 sin^3(t), y = 13 cos(t) - 5 cos(2t) - 2 cos(3t) - cos(4t), scaled to fit the screen.
- Treat each point as a complex number x + iy and run a discrete Fourier transform yourself: X_k = (1/N) * sum of x_n * e^(-2 pi i k n / N). Each coefficient becomes a circle with a frequency, a radius (its magnitude) and a starting angle (its phase). Map k above N/2 to negative frequencies.
- Sort the circles by radius, largest first. Each frame, chain them tip to tail at the current time and draw each circle and its radius line, faintly.
- The tip of the last circle traces the path: keep its positions in an array and draw them as an ink line.

Once that works, make it beautiful:
- Let me draw my own shape with the mouse or a finger. On release, resample the stroke to evenly spaced points, run the DFT, and let the circles redraw it.
- Cycle through a few built-in shapes when I'm idle, such as a star, a treble clef made from spline points, or a word written as one cursive stroke traced forward and then back.
- Use the arrow keys to halve or double how many circles are used, so I can see fewer circles give a smooth sketch and more add detail.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as tracing letters from a font, using an FFT for speed, or showing the frequency spectrum alongside.
PreviousBowed StringHelmholtz motion on a bowed violin string, with a Schelleng diagram measured live. NextDamascus SteelForge pattern-welded steel as a chain of exact maps, then grind and etch the blade.

Related visualizations

  • Fourier DarkroomMath Paint on a picture's 2D spectrum and watch the inverse FFT redraw it instantly.
  • Inscribed SquaresMath Every closed curve hides a square? Draw one and watch the hunt (open since 1911).
  • Apollonian GasketFractals An endless packing of kissing circles, each engraved with its exact integer curvature.
  • Circle PackingMath Thurston's discrete Riemann map: a live circle packing warps a picture into your blob.
  • Fourier FeaturesMachine learning A plain MLP, random Fourier features and a SIREN race to memorize one picture.
  • Hopf Fibration3D The 3-sphere as linked circles, projected into nested tori of pastel rings.
  • Space-Filling CurvesMath Hilbert, Peano, Gosper and friends fold smoothly from one order to the next.
  • Ford CirclesMath A circle for every fraction, and a dive into why the golden ratio is the most irrational.
  • Elliptic CurvesMath Chord-and-tangent addition on a real curve, rolled up into the finite-field torus.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs