Skip to content

Spirograph

By the end of this lab you'll be able to:

  • Plot a hypotrochoid (inner rolling circle) using parametric equations
  • Understand how R, r, and d control the petal and loop count
  • See how the ratio R/r determines when the curve closes

A Spirograph pattern — the curves made by a rolling circle inside a larger circle. Changing the three parameters R (outer radius), r (inner radius), and d (pen distance from center) produces hundreds of different patterns.

Welcome to the Spirograph!

Monty waving welcome Spirographs were a famous toy in the 1970s — now you can code one! A small circle rolls inside a big circle, with a pen attached to the small circle. The result: beautiful looping curves called hypotrochoids. Let's code it!

How It Works

x(t) = (R-r)*cos(t) + d*cos((R-r)/r * t) y(t) = (R-r)*sin(t) - d*sin((R-r)/r * t)

R is the outer circle radius, r the inner, d the pen offset from the inner center.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import turtle
import math
monty = turtle.Turtle()
monty.speed(0)
monty.hideturtle()

R = 130
r = 50
d = 90
steps = 3000
colors = ['royalblue', 'crimson', 'forestgreen']

monty.pencolor('royalblue')
monty.pensize(1)
monty.penup()

for i in range(steps + 1):
    t = 2 * math.pi * i / steps * r
    x = (R - r) * math.cos(t) + d * math.cos((R - r) / r * t)
    y = (R - r) * math.sin(t) - d * math.sin((R - r) / r * t)
    if i == 0:
        monty.goto(x, y)
        monty.pendown()
    else:
        monty.goto(x, y)

What Do You Think Will Happen?

Monty thinking R/r = 130/50 = 2.6. The curve loops R/r times — approximately how many petals? Make your guess — then click Run to find out!

Try It Now


  

A looping Spirograph curve — the inner circle rolls around 2.6 times for each full orbit, creating overlapping loops. Were you right?

How It Works

When R/r is a ratio of small integers (like 5/2), the curve closes perfectly after a small number of loops. When it's not a simple fraction, the curve takes many loops to close — or never closes at all.

Explanation Table

Line What it does
R = 130 Outer circle radius
r = 50 Inner rolling circle radius
d = 90 Pen distance from inner center
(R-r)*cos(t) + d*cos(...) Parametric x position
steps * r More loops for larger inner circles

Learning Check

Your Turn — Use Exact Integers

Monty thinking Change to R=100, r=40, d=70. This gives R/r = 5/2 exactly — a ratio of small integers. The curve should close perfectly after 2 orbits and have 5 petals. Predict and run!


  

R/r = 100/40 = 5/2 → a perfect 5-petaled hypotrochoid that closes cleanly after 2 orbits.

Experiments

  1. Try R=120, r=30 (ratio 4:1). You'll know it worked when a 4-lobed curve appears.

  2. Change d to a very small value. Try d = 10. You'll know it worked when the curve looks almost circular.

  3. Change d larger than r. Try d = 120 with the original parameters. You'll know it worked when the inner loops become larger.

  4. Try an epitrochoid (circle rolling outside). Change (R - r) to (R + r) in the formula. You'll know it worked when a different style of looped curve appears.

Spirograph Complete!

Monty celebrating You coded the math behind a real toy from the 1970s! These curves are called hypotrochoids — they're used in engineering to design Wankel rotary engines. Up next: Butterfly Curve — a trigonometric classic.