Skip to content

Spirograph Drawer

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

  • Draw a family of hypotrochoid curves that animate one after another
  • Use a list of parameter sets to create a sequence of different Spirograph patterns
  • Understand how changing R, r, and d produces completely different shapes

A Spirograph drawer that cycles through 6 different parameter sets, drawing each one in a different color to build up a layered display of overlapping hypotrochoid curves.

Welcome to the Spirograph Drawer!

Monty waving welcome In this lab the Spirograph draws itself — cycling through 6 different parameter sets automatically, building up a layered display! Let's code it together!

How It Works

A list of (R, r, d, color) tuples defines 6 Spirograph parameter sets. The outer loop iterates through them; the inner loop draws each hypotrochoid. tracer(0) and update() keep the animation smooth.

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
26
27
28
29
30
31
32
33
34
35
36
import turtle
import math

screen = turtle.Screen()
screen.tracer(0)
monty = turtle.Turtle()
monty.speed(0)
monty.hideturtle()

params = [
    (130, 50, 90, 'royalblue'),
    (100, 40, 70, 'crimson'),
    (120, 30, 80, 'forestgreen'),
    (110, 45, 85, 'darkorange'),
    (140, 60, 100, 'purple'),
    (100, 25, 75, 'teal'),
]

for R, r, d, color in params:
    monty.pencolor(color)
    monty.pensize(1)
    steps = 2000
    monty.penup()
    t0 = 0
    x0 = (R-r)*math.cos(t0) + d*math.cos((R-r)/r*t0)
    y0 = (R-r)*math.sin(t0) - d*math.sin((R-r)/r*t0)
    monty.goto(x0, y0)
    monty.pendown()
    for i in range(1, 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)
        monty.goto(x, y)
        if i % 50 == 0:
            screen.update()
    screen.update()

What Do You Think Will Happen?

Monty thinking Six different parameter sets in six different colors. Will the curves overlap neatly, or will they create a chaotic jumble? Make your guess — then click Run to find out!

Try It Now


  

Six colorful Spirograph curves, each with a different shape, building up a layered composition. Were you right about the overlap?

How It Works

Each (R, r, d) triple produces a completely unique curve. Because all curves are drawn from the same center, they overlap like layers in a painting. The if i % 50 == 0: screen.update() updates the display every 50 points to show the drawing progress.

Explanation Table

Line What it does
params = [...] List of (R, r, d, color) tuples
for R, r, d, color in params Unpack each parameter set
if i % 50 == 0: screen.update() Show progress every 50 steps
screen.tracer(0) Manual control over screen refresh

Learning Check

Your Turn — Design Your Own Set

Monty thinking Replace the params list with 3 parameter sets of your own choosing. Try to make curves that each have different numbers of loops (R/r ratio determines it). What ratios will you pick?


  

With the same R=120 and d=80 but different r values (40, 24, 15), the three curves have 3, 5, and 8 loops respectively — matching R/r.

Experiments

  1. Add more curves. Extend params to 10 entries. You'll know it worked when a denser, more colorful composition appears.

  2. Use pastel colors. Replace the colors with lighter shades. You'll know it worked when the overlapping curves produce a softer appearance.

  3. Clear and redraw. Add screen.clearscreen() between curves — only one at a time. You'll know it worked when each curve appears alone before the next one.

  4. Vary the step count. Use more steps for higher R/r ratios. You'll know it worked when complex curves look smoother.

Art Machine!

Monty celebrating Your code generates art automatically from a list of parameters — an art machine! This is the essence of generative art: code that produces visuals from rules. Up next: Category 11 — Advanced Patterns!