Author: Colin Price

Turtle Graphics
With the WeeBee Engine
Book 1

My First Name My Memory Stick

Drawing a Line

Load

File > Open > aTurtle1.cde

1. Add this line of code to place turtle1 at coordinates 10,10 .
add(turtle1,10,10);

2. Now add this line to set its pen down .
turtle1.setPenDown();

3. Now make it move forward a distance 30 like this,
turtle1.moveForward(30);

4. Now change the code to make it move a distance of 20. Try other distances.

Save

Using the Pen

Load

File > Open > aTurtle2.cde

1. Add this line of code to place turtle1 at coordinates 10,10 .
add(turtle1,10,10);

2. Now add these lines to set its pen down and move forward.
turtle1.setPenDown();
turtle1.moveForward(20);

3. Now let’s lift the pen up then move forward again.
turtle1.setPenUp();
turtle1.moveForward(20);

4. Now add these lines to set its pen down and move forward.
turtle1.setPenDown();
turtle1.moveForward(20);

So now you can get the turtle to draw a dashed line.

Save

Drawing with Colours

Load

File > Open > aTurtle3.cde

1. Now add these lines to set its pen down and then set its colour and move forward.
turtle1.setPenDown();
turtle1.setPenColour(blue);
turtle1.moveForward(20);

2. Try a different colour for your line. You can choose from the following:
red, blue, cyan, orange, yellow, green, black

3. Now add more lines of code to produce a dashed line with two different colours.

4. Now insert the following line before you make the turtle move.
turtle1.setPenWidth(5);
Then change the 5 to a different number and see what happens.

Save

Turning Corners

Load

File > Open > aTurtle4.cde

1. Add the following line to make the turtle turn left 90-degrees.
turtle1.rotate(-90);

2. Let’s make him move forward a bit.
turtle1.moveForward(20);

3. Now make him turn left a again then move forward.
turtle1.rotate(-90);
turtle1.moveForward(20);

4. Finally, a right turn.
turtle1.rotate(90);
turtle1.moveForward(20);

4. Investigate and Experiment! Change the numbers –90 and get the turtle to turn through smaller or larger angles. You can also change the pen width and the pen colour.

Save

Steps and a Staircase

Load

File > Open > aTurtle5.cde

1. Add code to make the turtle draw a single step like this .

2. Now add more code to draw a staircase. You can give it as many steps as you like. You can also set the pen colour and width before you get the turtle to move. Here’s what I did:

Save

Squares

Load

File > Open > aTurtle6.cde

1. Have a go at drawing a single square like this.
You can choose the colour and pen width.

2. Now change your code to draw a rectangle like this.

3. Let’s place a WeeBee in the rectangle. I will choose pip.
add(pip,10,10);
Oops, I got that wrong!

Save

Squares—the easy way

Load

File > Open > aTurtle7.cde

1. The turtle has a built-in function to draw a square for you. You can choose where to place the square and how large to make it. Here’s the code to add.
turtle1.drawSquare(30,20,15);
2. Do you understand what the three numbers 30, 20, 15 mean? Test yourself by changing them (one at a time).

2. Add more lines to make an interesting collection of squares. Choose colours to make a nice overall work of art. Here’s what I did:

Save

“Turtle—Go Home!”

Load

File > Open > aTurtle8.cde

1. Sometimes we need the turtle to “go home” (to its starting point) or move to another point without drawing a line. Here’s how to do it.
Open the file and you will see that the turtle starts from its home and then draws a square. Where is it’s home? (coordinates)
To get it to return home, add these line of code at the end.
turtle1.setPenUp();
turtle1.moveForwardTo(20,20);

2. Now add more code to make the turtle move to a location (you choose where), then draw a short line, then return home.
THINK about setting the pen up and down!

Save

Drawing a Flag

Load

File > Open > aTurtle9.cde

1. Let’s draw a flag! First get the turtle to move to a place to draw the bottom of the flag pole.
2. Now add code to get the turtle to draw the flag pole.
3. Now add code to draw the flag.
4. Send the turtle home.

2. Now put pip onto the flag. Use:
add(pip,X,Y);
where X and Y are the numbers where you want pip to be.

Save

Navigating Roads

Load

File > Open > aTurtle10.cde

Here’s a mini-challenge for you. Look at the picture below. You can see some paths in a grass field. The turtle has to get to pip, but can only travel on the roads, and not on the grass.

Here’s another mini-challenge. Change your code so that the turtle takes the longest path you can think of to reach pip.

Save

Challenging Roads

Load

File > Open > aTurtle11.cde

Here’s another mini-challenge. Oh no, not another one! Look at the roads shown below. Set a challenge for another pair (your teacher may help organise this).
You can add other characters, or scenery, at any place on the grass or roads.
Try to get the turtle to do something interesting.

Save

#

#