Drawing With Code: Turtle Graphics for Kids

ยท 2 min read ยท By the Tiny Coderz team

Turtle graphics is a classic way to learn programming. A little "turtle" holds a pen and moves around the screen following your instructions, drawing as it goes. It combines art with code, and the result is something your child can see right away.

The idea

Imagine telling a friend how to draw a square without showing them: "Go forward 100 steps. Turn right 90 degrees. Do that four times." That's what you write for the turtle.

Your first drawing

Python has a built-in turtle module. Type:

import turtle

pen = turtle.Turtle()

pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.forward(100)

turtle.done()

A window opens and the turtle draws a square. Notice how the same two lines repeat. That's a hint to use a loop.

Use a loop

import turtle

pen = turtle.Turtle()

for i in range(4):
    pen.forward(100)
    pen.right(90)

turtle.done()

Same square, with much less typing. Now change 4 to 3 and 90 to 120 to draw a triangle.

Draw a star

import turtle

pen = turtle.Turtle()
pen.color("gold")

for i in range(5):
    pen.forward(150)
    pen.right(144)

turtle.done()

Why 144? A five-pointed star turns by 144 degrees at each point. Ask your child to experiment with other angles and see what appears.

A colourful spiral

import turtle

pen = turtle.Turtle()
pen.speed(0)
colors = ["red", "orange", "yellow", "green", "blue", "purple"]

for i in range(60):
    pen.color(colors[i % 6])
    pen.forward(i * 3)
    pen.left(59)

turtle.done()

The % operator gives the remainder, which cycles through the six colours. Changing 59 to other numbers produces very different patterns.

Maths in disguise

Turtle drawing quietly teaches angles, shapes and patterns. To draw any regular shape with n sides, turn by 360 divided by n degrees at each corner. Children can discover this by experimenting.

Ideas to try

  1. Draw a house from a square and a triangle.
  2. Make a flower from circles (pen.circle(50)) rotated several times.
  3. Write your initials in block letters.
  4. Make a pattern of squares that rotates a little each time.

If it doesn't open a window

The turtle module needs a graphical display, so it won't run in some browser-based or online editors. If that's the case, use an environment that supports it, or try a drawing course that runs in the browser. Tiny Coderz's Painting with Code course uses the same pen-and-turn idea inside the app.

Next steps

Once the basics feel easy, try variables to control size and colour. See Python loops for kids for more on repetition, or take a look at coding project ideas by interest.

Try Python Fundamentals with your child

Every lesson in Python Fundamentals opens with an animated explanation, then a short practice. You can read a full sample lesson with no account.

Keep reading