4.5. Single and Multiple Turtles

The program below draws a shape we have seen before.

This works because the turtle zari is keeping track of its state as we call different procedures. When we say forward, the actual direction zari moves depends on what turns it has done so far.

If we introduce another turtle and use it to run some of the procedures, we will not get the same shape.

Every turtle object has its own state - it keeps track of its own position and color. So, when we created chad his position wasn’t the same as zari’s - all turtles start at the center of the screen (0, 0). Similarly, his direction starts out at the default (East).

Mixed up programs

The following program has one turtle, “jamal”, draw a capital L in blue and then another, “tina”, draw a line to the west in orange as shown below. The program should do all set-up, have “jamal” draw the L, and then have “tina” draw the line. Drag the blocks of statements from the left column to the right column and put them in the right order. Then click on Check to see if you are right.

../_images/TwoTurtles1N.png

The following program has one turtle, “jamal”, draw a line to the north in blue and then another, “tina”, draw a line to the east in orange as shown below. The program should import the turtle module, get the window to draw on, create the turtle “jamal”, have it draw a line to the north, then create the turtle “tina”, and have it draw a line to the east. Drag the blocks of statements from the left column to the right column and put them in the right order. Then click on Check to see if you are right.

../_images/TwoTurtlesLN.png
You have attempted of activities on this page