Spirographs (digital art)

From Schoolcoders wiki

Spirograph is a toy which uses plastic cogs and a biro to plot complex patterns. If you manage to avoid pricking yourself with the drawing pins or ripping the paper, you will probably find that the pen has run out, but apart from that it is great fun.

In this series we will learn how to create Spirograph patterns in Python, creating an SVG vector image file. This is the same format used by Inkscape, so you can open your creations and edit afterwards.


Here is what the toy looks like in real life:


Image by Multicherry

The idea is that you pin one of the large plastic rings to a piece on paper on a flat cork board. You then put one of the plastic circles inside the plastic ring, and put a biro through one of the holes. As you push the plastic circle round the inside of the plastic ring, the pen traces out a pattern (often a rose type shape). Depending on the size of the plastic circle, and which hole you put the pen in, there are a variety of different shapes. You can also overlay multiple patterns, perhaps in different colours, to make more comples designs.

Alternatively, of course, you can do it with code instead, which some of us find easier and less dangerous.

How Spirograph patterns work

Here is an animation of a spirograph pattern being created:


The maths

A Spirograph curve is a type of Hypotrochoid curve. We will need the equations from that section to implement a Spirograph in code.

Python implementation

A simple Python version of the Spirograph code, using the pycairo graphics library, is given here.

See also