Section 16.5 Single and Multiple Turtles
The program below draws a shape we have seen before.
Checkpoint 16.5.1.
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 was not 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
Checkpoint 16.5.2.
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.
from turtle import *
---
jamal = Turtle()
jamal.pensize(10)
jamal.color("blue")
---
jamal.right(90)
jamal.forward(150)
---
jamal.left(90)
jamal.forward(150) #paired
---
jamal.left(90)
jamal.forward(75)
---
jamal.right(90)
jamal.forward(75) #paired
---
tina = Turtle()
tina.pensize(10)
tina.color("orange")
---
tina = Turtle()
tina.pensize(10)
tina.color(orange) #paired
---
tina.left(180)
tina.forward(75)
Checkpoint 16.5.3.
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.
from turtle import *
---
from turtle #paired
---
jamal = Turtle()
---
jamal = turtle() #paired
---
jamal.color("blue")
jamal.pensize(10)
jamal.left(90)
jamal.forward(150)
---
tina = Turtle()
tina.pensize(10)
---
tina.color("orange")
tina.forward(150)
---
tina.color("orange")
tina.Forward(150) #paired
You have attempted
of
activities on this page.