Turtle

Welcome to the Turtle Graphics page! Here, you can write turtle-style scripts to draw on the canvas below. Use simple commands to move the turtle, control the pen, and create fun shapes or patterns. Try out the sample script or make your own. Click "run" to see your drawing come to life!

not working

How to Use Turtle Graphics

You can tell the turtle what to draw by writing commands! The turtle starts in the middle of the canvas facing up. Write your commands and click "run" to see the magic happen!

Moving the Turtle

Make the turtle walk forward or backward:

move forward 50 steps
move backward 30 steps

Turning the Turtle

Make the turtle turn left or right:

turn 90 degrees to the right
turn 45 degrees to the left

A full circle is 360 degrees. 90 degrees is a right angle (like a corner of a square).

Drawing with the Pencil

Control when the turtle draws:

lower pencil    (start drawing)
raise pencil    (stop drawing, move without drawing)

When the pencil is "lowered", the turtle draws a line as it moves. When it's "raised", the turtle moves without drawing.

Changing Colors

You can use these colors: blue, red, green, yellow, black, white, orange, purple, brown, grey, fuchsia, maroon, rebeccapurple

use pencil of colour red
use pencil of colour blue

Changing Pencil Size

Make the line thicker or thinner:

use pencil of size 5
use pencil of size 10

Bigger numbers make thicker lines!

Using Variables

You can save numbers with names to use later:

size = 50
move forward size steps

Now you can use "size" instead of writing 50 every time!

Math Operations

You can do math with numbers:

  • + for addition (5 + 3 = 8)
  • - for subtraction (10 - 4 = 6)
  • * for multiplication (3 * 4 = 12)
  • / or : for division (12 / 3 = 4)
  • ^ for power (2 ^ 3 = 8, which is 2×2×2)
  • sqrt for square root (sqrt(16) = 4)
distance = 20 + 30
move forward distance steps

Repeating Things (Loops)

Draw the same thing many times with a "for" loop:

for i from 1 to 4
    move forward 50 steps
    turn 90 degrees to the right
end

This draws a square! The turtle repeats the commands inside 4 times.

You can also use a "while" loop to repeat while something is true:

i = 0
while i < 10
    move forward 10 steps
    turn 36 degrees to the left
    i = i + 1
end

This keeps going while i is less than 10, drawing a circle!

Making Decisions (If/Then)

Make the turtle do different things based on conditions:

if x > 100
    then
        turn 90 degrees to the left
    else
        move forward 10 steps
end

You can compare numbers with: == (equal), != (not equal), > (greater), < (less), >= (greater or equal), <= (less or equal)

Example: Drawing a Square

lower pencil
use pencil of colour blue
use pencil of size 3
for i from 0 to 4
    move forward 100 steps
    turn 90 degrees to the right
end
raise pencil

Example: Drawing a Star

lower pencil
use pencil of colour yellow
use pencil of size 5
for i from 1 to 6
move forward 80 steps
turn 144 degrees to the right
end
raise pencil

Example: Drawing a Spiral

lower pencil
use pencil of colour green
s = 1
for i from 1 to 80
move forward s steps
turn 18 degrees to the left
s = s + 1
end
raise pencil

Tips

  • Always start with "lower pencil" if you want to draw
  • Use "raise pencil" when you want to move without drawing
  • Remember to close your loops with "end"
  • You can use variables to make your code easier to change
  • Try different colors and sizes to make your drawings more fun!