A spirograph draws beautiful mathematical curves by rolling a circle inside or outside a fixed circle. The pen is attached at some distance from the rolling circle's centre, tracing out a parametric path called a hypotrochoid (inner rolling) or epitrochoid (outer rolling).
2π · r / gcd(R, r).Hypotrochoid (inner rolling):
x(t) = (R−r)·cos(t) + d·cos((R−r)/r · t)
y(t) = (R−r)·sin(t) − d·sin((R−r)/r · t)
Epitrochoid (outer rolling):
x(t) = (R+r)·cos(t) − d·cos((R+r)/r · t)
y(t) = (R+r)·sin(t) − d·sin((R+r)/r · t)
Period: T = 2π · r / gcd(R, r)
When R = 2r in a hypotrochoid, the rolling circle fits inside the fixed circle exactly twice, and the pen traces a straight-line diameter — seemingly impossible from a mechanical toy! Setting r = R and d = r in epitrochoid mode gives a cardioid, the iconic heart-shaped curve found in the Mandelbrot set's main bulb and in coffee-cup caustics.
Explore parametric rolling-circle curves interactively. A hypotrochoid is traced when a small circle rolls inside a fixed ring; an epitrochoid when it rolls outside. By adjusting the outer radius R, rolling radius r, and pen offset d, you can produce an endless variety of roses, stars, looping petals, and the famous cardioid — all from one simple mechanical principle.
What is a hypotrochoid?
A hypotrochoid is a curve traced by a point attached to a small circle rolling inside a larger fixed circle. The parametric equations are x(t) = (R−r)cos(t) + d·cos((R−r)/r · t) and y(t) = (R−r)sin(t) − d·sin((R−r)/r · t), where R is the outer radius, r the rolling circle radius, and d the pen distance from the rolling circle's centre.
What is an epitrochoid?
An epitrochoid is traced by a point on a circle rolling outside a fixed circle. Its equations are x(t) = (R+r)cos(t) − d·cos((R+r)/r · t) and y(t) = (R+r)sin(t) − d·sin((R+r)/r · t). Famous examples include the cardioid (d = r, r = R) and the limaçon.
How does a spirograph toy work?
A spirograph toy uses toothed plastic rings and gears. A smaller gear is placed inside (or outside) the fixed ring, and a pen is inserted in one of the holes. As the gear rolls around, the pen traces a hypotrochoid or epitrochoid. The ratio R/r and the hole position d determine the pattern.
The curve closes after a full period of 2π · r / gcd(R, r) in t, which corresponds to r / gcd(R, r) full rotations of the rolling circle and R / gcd(R, r) trips around the fixed circle. If R/r is irrational the curve never exactly closes and fills an annulus densely.
A cardioid is an epitrochoid with r = R and d = r. Its name comes from the Greek word for heart. It appears in many physical contexts: the microphone pickup pattern, the boundary of the main bulb of the Mandelbrot set, and in optics as a caustic in a coffee cup.
A rose curve (rhodonea) appears when d = R − r (the pen is on the circumference of the rolling circle) and r divides R. The number of petals equals R/r if R/r is odd, or 2R/r if R/r is even. Try R = 120, r = 40, d = 80 for a three-petal rose.
Spirograph curves are Fourier epicycles in disguise: each sinusoidal term in the parametric sum corresponds to one harmonic frequency. Hypotrochoids and epitrochoids are also special cases of Roulettes — curves generated by rolling one curve along another — studied by Euler and Bernoulli.
The greatest common divisor (GCD) of R and r determines the curve's period. Only the reduced ratio (R − r)/r matters for the shape. Curves with the same ratio but different absolute radii look identical. A GCD of 1 means the smallest gear must make R revolutions before the pattern repeats.
When d > r the pen extends beyond the rolling circle's edge, producing looping or prolate curves with inner loops. For hypotrochoids with d > r the curve can extend outside the fixed ring region. When d = r the curve passes through the centre of the rolling path, and when d < r the curve stays within the annulus between radii |R−r−d| and R−r+d.
Both are parametric curves with sinusoidal components but differ in structure. Lissajous figures use x = A·sin(at + δ), y = B·sin(bt) with independent amplitudes and frequencies, while spirograph curves couple amplitude and frequency through the rolling geometry. When R/r = 2 the hypotrochoid degenerates into a straight line, a degenerate Lissajous, showing the deep connection.
This simulation is a digital spirograph: it plots the path traced by a pen mounted on a small circle of radius r that rolls, without slipping, either inside or outside a larger fixed circle of radius R. The pen sits a distance d from the rolling circle's centre. Whilst the mechanics are simple, the resulting hypotrochoid and epitrochoid curves range from tidy roses and stars to the heart-shaped cardioid, all governed by a handful of parametric equations updated live as you drag the sliders.
Two families of roulette curves. In Hypotrochoid mode the small circle rolls inside the fixed ring, giving x(t) = (R−r)cos(t) + d·cos((R−r)/r·t); in Epitrochoid mode it rolls outside, giving x(t) = (R+r)cos(t) − d·cos((R+r)/r·t), with the matching sine term for y(t). Setting r = R and d = r in Epitrochoid mode produces a true cardioid, and the drawing always closes after a period of 2π·r/gcd(R, r).
Toggle Hypotrochoid / Epitrochoid to switch rolling mode, then drag Outer radius R (50–200), Rolling radius r (5–100) and Pen offset d (1–200) to reshape the curve. Draw speed (1–20) sets how many angle steps are plotted per frame, and Hue shift (0–360°) rotates the stroke colour. Pause/Play freezes the drawing, Reset clears the canvas and redraws from t = 0, and Info opens a panel with the full equations.
When the radius ratio R/r is exactly 2, a hypotrochoid degenerates into a straight line segment — the pen appears to move back and forth through the centre, even though it is still following the same rolling-circle equations that produce loops elsewhere.
A hypotrochoid is traced by a circle rolling inside a fixed ring, using x(t) = (R−r)cos(t) + d·cos((R−r)/r·t) and y(t) = (R−r)sin(t) − d·sin((R−r)/r·t). An epitrochoid is traced by a circle rolling outside a fixed circle, using the same form with plus signs: x(t) = (R+r)cos(t) − d·cos((R+r)/r·t). Switching between the two changes which side of R the rolling circle sits on.
Switch to Epitrochoid mode, then set the rolling radius r equal to the outer radius R and set the pen offset d equal to r as well. With r = R and d = r the epitrochoid equations simplify to the classic cardioid, the heart-shaped curve also seen in microphone pickup patterns and the main bulb of the Mandelbrot set.
The drawing repeats after a period of 2π·r/gcd(R, r) in the parameter t. If R and r share a large common factor the curve closes quickly with few loops; if their greatest common divisor is small, the pen must sweep round many more times before the pattern joins back onto itself.
Rose-like hypotrochoids appear when the pen offset d equals R − r and r divides evenly into R. The petal count then equals R/r when that ratio is odd, or twice R/r when it is even. Try R = 120, r = 40 and d = 80 for a clean three-petal rose.
When d exceeds r the pen sits beyond the edge of the rolling circle, so the traced curve grows extra loops instead of staying smooth. When d equals r the curve passes cleanly through the centre of the rolling path, and when d is smaller than r the whole curve stays within a narrow ring around radius R − r.