← Home

epicycles

A drawing machine that redraws images as sums of rotating circles


Links

Date

2026

Built a drawing machine that takes an image and redraws it with stacked rotating circles, a complex Fourier series you can watch work. Drop in a logo or sketch a path by hand, and it extracts the outlines, runs a DFT on each one, and drives chains of epicycles whose tips trace the drawing in ink. Inspired by this Mathologer video on epicycles and Homer Simpson's orbit. This was a really fun project, and I mostly wanted to feel the magic of Fourier transforms.

How it works

The image becomes closed paths first. Flat-color art is segmented by palette: cluster the colors, vote out the background using the image border, and trace each remaining region with marching squares. Photos fall back to an Otsu-thresholded silhouette or Sobel edges. SVGs get re-authored to 1024px before rasterizing so small icons don't trace jagged. Every path found this way gets its own machine, and they all draw simultaneously.

The math

Each path is resampled to M=512M = 512 evenly spaced points and read as one period of a complex signal, treating the drawing plane as the complex plane:

zm=xm+iym,m=0,1,,M1z_m = x_m + i\,y_m, \qquad m = 0, 1, \ldots, M-1

The discrete Fourier transform decomposes that signal into MM coefficients:

Xk=1Mm=0M1zmei2πkm/MX_k = \frac{1}{M} \sum_{m=0}^{M-1} z_m\, e^{-i 2\pi k m / M}

Each coefficient is a circle. Writing Xk=akeiφkX_k = a_k e^{i\varphi_k}, the amplitude aka_k is the circle's radius, the signed frequency kk is how fast it spins and in which direction, and the phase φk\varphi_k is where it starts. Stack the circles tip to tail, big ones first, and the pen is the partial sum

z(t)=kXkeiktz(t) = \sum_{k} X_k\, e^{i k t}

over the nn largest-amplitude terms. With all MM terms the inverse transform reproduces the sampled path exactly; with fewer, you watch the approximation converge.

The n slider

Truncation error is the fun part. At n=5n = 5 the machine draws a wobbly approximation, at n=40n = 40 the shape is unmistakable, and with all 512 terms the reconstruction is exact to floating point. Half the circles spin clockwise: you can't close a non-circular curve without negative frequencies.