The maths behind the Spirograph toy.

A year ago, I was introduced to the Spirograph toy when I was looking for a gift I could 3-D print for a friend. (Yes, Iβm 20 years late.) Whilst I was realising what was missing from my childhood and wasting tons of paper, I could not stop thinking about the maths behind it. So here is a fun post about the maths behind the Spirograph toy, complete with some nice curves created using my Spirograph web app.
Letβs start with the equation of the curves formed by the Spirograph toy. In order to understand how the Spirograph works, we need to first learn some geometry of curves.
A roulette is the curve traced by a fixed point on a closed convex curve that rolls along another secondary curve without slipping.


The Spirograph toy traces out two kinds of roulettes, namely hypotrochoids and epitrochoids.
A hypotrochoid is a roulette in which the fixed point is attached to a circle that rolls inside a stationary circle. We can draw hypotrochoids with the Spirograph by rolling the wheel around the inside of the ring.
![]() | ![]() |
|---|
Let

The centre of the rotating circle is always
We also need to derive the position of the fixed point relative to the centre of the rotating circle.
(Note that in the animation above, the fixed point is outside the rotating circle. Whilst this fixed point is still βattachedβ to the rotating circle, making it a hypotrochoid, this technically is not possible with the physical Spirograph toy.)
Because the parameter
Why is it negative? Well, if we have the rotating circle move inside the fixed circle in a counterclockwise direction, like in the animation above, we can see that the circle actually rotates in a clockwise direction. This means that our fixed point will always move around the centre of the rotating circle in the opposite direction that the rotating circle moves around the centre of the fixed circle.
Our fixed point also obeys circular motion, therefore the parametric equations for the fixed point relative to the centre of the rotating circle are:
We can now add the
An epitrochoid is a roulette in which the fixed point is attached to a circle that rolls along the outside of a stationary circle. We can draw epitrochoids with the toy by rolling the wheel around the outside of the ring.
![]() | ![]() |
|---|
Again let

Our parametric equations for an epitrochoid are similar to the hypotrochoid. Instead, the centre of the rotating circle is always
Thus, the parametric equations for an epitrochoid are:
As we saw earlier, these parametric equations can be split into two terms. The first term (e.g. updateSpiro() function of the web app, we get:
posr = {
x: mainCanvas.width / 2 + (R - r) * Math.cos(t),
y: mainCanvas.height / 2 + (R - r) * Math.sin(t),
};
for a hypotrochoid, and
posr = {
x: mainCanvas.width / 2 + (R + r) * Math.cos(t),
y: mainCanvas.height / 2 + (R + r) * Math.sin(t),
};
for an epitrochoid. This allows us to draw the rotating circle rolling around the stationary circle.
The second term (e.g. updateSpiro() function below the previous lines, we get:
posPen = {
x: posr.x + p * Math.cos(((R - r) / r) * t),
y: posr.y - p * Math.sin(((R - r) / r) * t),
};
for a hypotrochoid, and
posPen = {
x: posr.x - p * Math.cos(((R + r) / r) * t),
y: posr.y - p * Math.sin(((R + r) / r) * t),
};
for an epitrochoid. Now that we have the absolute position of the fixed point, or pen, we can display the actual result of the spirograph.
Letβs recall that our parameter
(In my Spirograph web app, I use this fact to ensure that the parametric equations for generating the multi-colour gradient pen ends at
Fortunately, calculating the
where
// Calculate the greatest common divisor of two numbers
function gcd(x, y) {
while (y) {
var tmp = y;
y = x % y;
x = tmp;
}
return x;
}
Now we can calculate the number of petals a Spirograph curve will have. Inserted below are a hypotrochoid and epitrochoid drawn using the same values:
![]() | ![]() |
|---|
If you count the number of petals for both the hypotrochoid and epitrochoid, both the hypotrochoid and epitrochoid have 25 petals. Letβs check that:
Hypocycloids and epicycloids are very similar to hypotrochoids and epitrochoids, however the fixed point is always on the circumference of the rotating circle. This means that we can reduce the equation for a hypotrochoid and epitrochoid to that for a hypocycloid and epicycloid.
This time, letβs say the radius of the larger circle
for a hypocycloid, and
for an epicycloid. Why write it in this way instead? The number of cusps, or sharp corners on the curve, is directly correlated to the ratio of the radius of larger circle to the radius of the smaller circle, or
If
| k = 3 | k = 4 | k = 5 | k = 6 | k = 7 |
|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
| k = 1 | k = 2 | k = 3 | k = 4 | k = 5 |
|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
If
| k = | k = | k = | k = | k = |
|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
| k = | k = | k = | k = | k = |
|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
If