Home
Project Folders
Teacher Resources
Student Resources
En ESPAÑOL
How Do I?
Vocabulary
MWForum
Site Map
Search
Our Team

polygons 1 2 3 4 5 6 7 8 9
Polygons 4
Download
5 KB


Goal:   One turtle chases another around a polygon.


Screenshot


Vocabulary:   pu, wait, towards, distance, everyone, home

Code
Project Map

to polygon
t1, pd
setc whatcolor
setpensize howthick
repeat #sides [fd howbig rt 360 / #sides]
end

to polygon-chase
t1, pd
setc whatcolor
setpensize howthick
fd howbig rt 360 / #sides
t2, pu
towards "t1
wait 3
fd distance "t1
wait 3
end

to reset
everyone [home]
cg
end



Notes

  1. Hatch a second turtle (t2).   This turtle will follow the first turtle (t1).

    Write a polygon-chase procedure as shown.

  2. t1, means that we are talking to the first turtle.   (We could also write: tto "t1 - this stands for talkto "t1.)

  3. Wait 3 means "wait 3/10 of a second."   This slows the turtles down so we can see what they are doing.  

  4. 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.)

  5. towards "t1 sets turtle t2's heading to aim towards turtle t1.

  6. 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.

  7. 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.

  8. Create a button and name it polygon-chase.   Set it to Forever.   Try it! Click the button again to stop the action.

  9. In the revised reset procedure, everyone [home] returns both turtles to the center of the page, pointing straight up.  




What If?
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?)


Challenge
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.)





© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.