A piece from the gallery

Turtle drawings

Every line in this spiral was drawn by following just three instructions, over and over. How few instructions do you think it takes?

Meet the turtle

Picture a tiny turtle sitting on a sheet of paper, holding a pen. It isn't very clever. It only understands two things:

  • forward 100: walk 100 steps straight ahead, drawing a line.
  • turn 90: turn on the spot by 90 degrees, a quarter of the way around.

Ask it to go forward and turn four times, and it draws a square. To save typing it all out, you can say repeat 4 [ forward 100 turn 90 ], which means "do the bit in brackets four times."

Turtle graphics: drawing by giving a pen simple directions like these. The idea goes back to the Logo programming language of the late 1960s, where children sometimes steered a real little robot "turtle" across the floor.

Change one number, get a new world

Keep everything else the same and change only how far the turtle turns. Look what happens.

Turn 90°: a square
Turn 144°: a star
Turn 170°: a sunburst
Turn 121° and grow a little each time: a twisting spiral

Why does 144° make a star? Five turns of 144° add up to 720°, which is two full turns. So the turtle comes home to where it started, but only after looping around twice, and that crossing-over is what makes the points.

Draw with the turtle

Move the sliders or pick an example. When you're ready, switch to typing the steps yourself.

Your browser needs JavaScript turned on for the turtle to draw.

What the turtle is doing: repeat 150 [ forward 2 turn 121 grow 2 ]

Things to try

  • Start with the Star, then nudge the turn a degree or two either side of 144°. How quickly does it stop closing up?
  • Try a turn of 89° or 91° with the Square spiral. A tiny change makes it twist.
  • Open the Flower in typing mode and change the 30 at the end to 45. How many petals now?

No coding experience needed

The sliders are all you need to start. The typed steps are there when curiosity pulls you further, and the turtle explains plainly when it doesn't understand something.

In a classroom, try asking everyone to guess what a turn of 72° or 160° will draw before pressing anything. The guessing is half the fun.

Where next?

The turtle repeats one small set of steps. The Koch snowflake repeats one small rule on every edge, until the shape becomes endlessly detailed.