A circle rolling inside a ring
A spirograph curve comes from one simple physical setup: a small circle of radius r rolls, without slipping, around the inside of a fixed ring of radius R. A pen held at distance d from the small circle's centre traces a curve called a hypotrochoid as the whole system turns. Roll the same small circle around the outside of the ring instead and the pen traces an epitrochoid. Both curves are governed by the exact same idea, only the sign of one term flips.
The parametric equations
Both curves come from the same construction: the small circle's centre orbits the ring's centre, and the pen point additionally rotates around the small circle's centre at a rate set by the rolling-without-slipping constraint.
Hypotrochoid (rolling INSIDE the ring): 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 (rolling OUTSIDE the ring): x(t) = (R + r)·cos(t) - d·cos( (R + r)/r · t ) y(t) = (R + r)·sin(t) - d·sin( (R + r)/r · t ) special case d = r → hypocycloid / epicycloid (cusps touch the ring) special case R = r, d = r, epitrochoid → the cardioid
The first term of each equation traces the slow circular motion of the small circle's centre around the ring; the second term adds the pen's own faster rotation around that moving centre, at an angular rate scaled by the ratio of the two radii. It is the interference between these two rotations, one slow and one fast, that produces the looping rosette pattern rather than a plain circle.
Why the ratio R/r controls the petal count
Write the ratio of the two radii in lowest terms as R/r = p/q. The curve closes on itself precisely when the small circle has completed q full trips around the inside of the ring, and in that time the pen has swung around p times relative to the ring — the closed curve ends up with p cusps (if d = r) or p smooth lobes (if d ≠ r). This is exactly why the classic plastic Spirograph toy, whose gears have small whole numbers of teeth, always closes after a short, predictable number of turns — the tooth counts fix p and q as small integers by construction.
Dial in an irrational ratio — something a toothed gear can never physically produce, but a continuous simulation can — and the curve never closes at all. Instead the pen path fills the ring ever more densely, sweeping out a shape that approaches (but never becomes) a filled annulus, a nice concrete illustration of the difference between rational and irrational numbers that you can watch happen on screen.
From spirograph to cardioid and beyond
The whole family of "-oid" curves familiar from calculus courses is just special settings of the same two equations. Set d = r and you get a hypocycloid or epicycloid, with sharp cusps exactly touching the outer ring — three cusps at R/r = 3 gives the deltoid, four gives the astroid. Set R = r in the epitrochoid case with d = r and the two-lobed epicycloid collapses into a single heart-shaped curve: the cardioid, the same curve that appears as the boundary caustic on the surface of a cup of coffee lit from one side, and as the main body of the Mandelbrot set.
Rendering it well
Because the curve is fully parametric, drawing it is just sampling t at a fine enough step and connecting the dots — no differential equation, no numerical integrator, no accumulated error. The only care needed is choosing the sampling range: to see the full closed curve you must run t from 0 to 2π·q (not just 2π), where q is the denominator of the reduced ratio R/r, otherwise the curve will look "cut off" partway through its pattern even though the maths is correct.
Frequently asked questions
What decides how many petals a spirograph curve has?
The reduced ratio R/r. If R/r = p/q in lowest terms, a hypotrochoid closes after the small circle has rolled q times around the inside of the ring and traces a pattern with p cusps or lobes when d = r (a hypocycloid). Irrational ratios never exactly close and instead fill the ring with an ever-denser rosette.
What is the difference between a hypotrochoid and a hypocycloid?
A hypocycloid is the special case where the tracing point sits exactly on the rolling circle's rim (d = r), which produces sharp cusps touching the outer ring. A hypotrochoid is the general case with the pen offset d anywhere else — inside the rolling circle it produces smooth, rounded loops instead of cusps, which is what a real spirograph toy draws because the pen hole is never at the very edge.
Why does the classic Spirograph toy only ever draw closed curves?
Because its gears have a fixed, small integer number of teeth, R and r are always commensurable — their ratio is always a ratio of whole numbers — so the curve is guaranteed to close after a finite, predictable number of turns. A continuous simulation can dial in an irrational ratio, which a toothed gear physically cannot do, and watch the curve spiral forever without ever closing.
Try it live
Everything above runs in your browser — open Spirograph and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Spirograph simulation