Epicycles
ABOUT THE APP
Open Epicycles ← Projects
About the app

Epicycles

Draw a circle. Now put a second, smaller circle on its edge, and a third on the edge of that one, and let them all spin. The pen on the last circle traces a strange path. Choose the right sizes and speeds, and that path can be any shape you like: a heart, your name, a face. Epicycles finds those circles for any picture and shows them at work.

Open Epicycles →

What it does

  • Takes any pictureType some text, pick a heart, a star or a gear, draw your own, or upload a photo. Your photo stays on your device: it is never sent anywhere.
  • Cleans it upPhotos are full of tiny details, like skin pores, grass or fabric, that would turn into scribble. A preparation window blurs them away, turns the background white and makes light areas white too.
  • Turns it into one lineLike a connect-the-dots puzzle: the picture becomes dots, and the dots are joined into one line that ends where it started.
  • Draws it with circlesFirst with 1 circle on each side, then 2, then 3, and so on up to 500. Watch the drawing get sharper with every step. You can zoom in, or let the view follow the pen.
  • Shows the numbersHow far the drawing is from the line, and the size, starting angle and speed of every circle. You can save the drawing as an SVG file. In English, Spanish and Danish.

Author

Epicycles was designed and built by Daniel Alberto Sepulveda Estay, PhD, founder of Estay Dynamics. He works on system dynamics and network optimisation for supply chain resilience. He holds a PhD from the Technical University of Denmark and an MSc from the Massachusetts Institute of Technology, and is a council member of the System Dynamics Society.

More about Daniel →

To cite: Sepulveda Estay, D. A. (2026). Epicycles: a picture drawn by turning circles (version 1.3.1) [Software]. https://kathuman.github.io/claude-projects/epicycles/

The maths, step by step

You only need to know what a circle, sine and cosine are. Everything else is built from there.

1. One spinning circle

A pen sits on the edge of a circle with radius r. When the circle has turned by an angle θ, the pen is at

x = r · cos θ     y = r · sin θ

Let a clock t run from 0 to 2π: that is one round. If the circle turns k times during one round, its angle is θ = k·t + φ. The Greek letter φ (phi) is just where it starts. So k is the circle's speed: a circle with k = 3 spins three times as fast as one with k = 1.

2. Circles on circles

Put the centre of circle 2 on the pen of circle 1, the centre of circle 3 on the pen of circle 2, and so on. The left–right position of the last pen is simply all the steps added up:

x(t) = a₀ + r₁ cos(t + φ₁) + r₂ cos(2t + φ₂) + r₃ cos(3t + φ₃) + …

Here a₀ is where the chain starts. Circle 1 turns once per round, circle 2 twice, circle 3 three times. The up–down position y(t) gets a sum just like it, with its own circles. That is why the app has two chains: the one above the picture moves the pen left and right, the one on the left moves it up and down, and the dashed guide lines meet at the pen.

3. From a picture to one line

The app finds the outlines or edges in the picture, or places dots where it is dark, and joins the dots like a connect-the-dots puzzle: start anywhere and always go to the nearest dot you have not visited yet. Then it fixes crossings: if two pieces of the line cross like an X, flipping the part in between always makes the line shorter, so it keeps flipping until nothing crosses. Finally it puts 1,024 points evenly along the line, at the times

tj = 2π · j / 1024,   j = 0, 1, 2, …, 1023

4. How big is each circle?

To find circle k, multiply each point of the line by a circle that turns k times, and take the average. The sign Σ means “add up over all the points j”:

ak = (2/1024) · Σ xj · cos(k tj)     bk = (2/1024) · Σ xj · sin(k tj)
rk = √(ak² + bk²)     φk = the angle of the point (ak, −bk)

Why does this work? If the line swings back and forth in step with a circle turning k times, the products are mostly positive and the average is large: that circle is big. If they do not match, the products are positive half the time and negative half the time, and they cancel out to almost zero. a₀, the start of the chain, is just the average of all the xj. This recipe is called a Fourier series, after Joseph Fourier, who found it in 1807.

5. How close is the drawing?

Every circle carries its own share of the line's movement, equal to r²/2. Leave some circles out and you lose exactly their shares. So the error with N circles is

errorN = √( sum of r²/2 for the circles left out ÷ sum of r²/2 for all circles )

Adding a circle can only make the error smaller, never bigger, and with all the circles it is zero. This is the “Distance from the line” number in the app, and the falling curve in its chart. (Mathematicians call this Parseval's theorem.)

6. Taylor or Fourier?

You may have met a Taylor series, which builds a curve from powers of t:

x(t) = c₀ + c₁t + c₂t² + c₃t³ + …

Powers of t keep growing, so this curve never comes back to where it started, and it cannot draw a closed loop. But here is the trick. Let z be a point going once round a circle of radius 1 in each round, written z = eit. Then z² goes round twice as fast, z³ three times as fast, and so on, and

x(t) = Re( A₀ + A₁z + A₂z² + A₃z³ + … ),   with Ak = rk eiφk

is a Taylor series too, but in z instead of t. (“Re” means: take only the left–right part.) Each power zk is one of our circles, and its place in the series is its speed.

How do we know it works?

The app checks itself with more than 80 automatic tests. A few of them: give it a perfect circle, and it must find exactly one circle per side. Give it a square, and all the circles together must rebuild the square. Adding a circle must never make the error bigger. Every dot must be visited exactly once, and untangling must never make the line longer. Everything runs in your browser.