Add More Turtles!
Goals:
- Work with sprites, computer graphics that may be moved and otherwise manipulated as individual entities.
- Begin to develop an understanding of why the order of statements in our code does not always agree with the order that things actually happen when we run that code.
Coding Snippets:
- The
Turtleconstructor's color parameter is optional. The default color is green. Usewearto change an existing turtle's color. - Sprites passed to
syncmust finish all instructions preceding that call tosyncbefore any of them can move on to instructions appearing aftersync. cs(clear screen) will delete all graphics as well as all sprites other than the default.cg(clear graphics) clears only what is drawn on the canvas.
Math and Computer Concepts:
- Use a special function called a constructor to create additional sprites. Constructors have names that begin with capital letters, and are invoked with the
newoperator. In this lesson we will use theTurtleconstructor to make additional turtles. - Additional sprites need to be named, such as
rin the coding snippet above.turtleis the name for the green, default sprite.
- Use dot notation to refer to a specific sprite. For example,
t.fd 50moves turtletforward ands.rt 90makes turtlesturn right.turtle.fd 20works the same asfd 20.
Activities:
Save all programs for this lesson in a folder called Turtles.
- Copy the code above to a program SyncTest, and run it. Then insert the statement
sync r,bbefore the statementb.rt 360,100. You should get the following, illustrating the effect ofsync: - RandomTurtles: make a program with several differently-colored turtles that move about randomly (use iteration, and use the
randomfunction to determine how far each turtle moves and/or turns). Have your turtles draw lines or dots along the way. - TeamTurtles: write a program with multiple turtles that work in unison to make a creative, symmetric design. The turtles should be synced so they move in unison.
- TurtleRace: set up a race between two or more turtles. Use a loop and the random function to control their forward movement, e.g.,
turtle.fd random(10).



