Goal: One turtle chases another around a polygon.
Vocabulary: pu, wait, towards, distance, everyone, home
repeat #sides [fd howbig rt 360 / #sides]
fd howbig rt 360 / #sides
fd distance "t1
- Hatch a second turtle (t2). This turtle will follow the first turtle (t1).
Write a polygon-chase procedure as shown.
- t1, means that we are talking to the first turtle. (We could also write: tto "t1 - this stands for talkto "t1.)
- Wait 3 means "wait 3/10 of a second." This slows the turtles down so we can see what they are doing.
- Pu means "pen up." (A newly-hatched turtle starts out with its pen up, so this command is not really necessary, but it reminds us of one difference between t1 and t2: t1 is the drawing turtle; t2 is the following turtle.)
- towards "t1 sets turtle t2's heading to aim towards turtle t1.
- fd distance "t1 moves t2 forward the distance between it and t1. In this case, because t2 is facing towards t1 before it begins moving, t2 will now sit directly upon t1.
- Each time the polygon-chase procedure repeats, first t1 moves ahead to the next vertex (corner) based on the slider inputs, and then t2 moves ahead based entirely on t1's movements.
- Create a button and name it polygon-chase. Set it to Forever. Try it! Click the button again to stop the action.
- In the revised reset procedure, everyone [home] returns both turtles to the center of the page, pointing straight up.
Try different numbers after wait. (How do the turtles move if the first wait command uses a larger input than the second wait command? How do the turtles move if the first wait command uses a smaller input than the second wait command?)
Can you revise the polygon-chase procedure so that turtle t1 chases turtle t2?
On Your Own - Project Ideas
Create a geometric design such as a zigzag, drawn while one turtle slowly chases another turtle. (Consider having both turtles put their pen down and set their pens to different colors and thicknesses.)