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

ant hill 1 2 3 4 5 6
Ant Hill 2
Download
7 KB


Goal:   Set up a compass to show the ant´s direction.


Screenshot


Vocabulary:   pd, ht, freezebg, clean, setpos, bk (back), settext1, heading, show, pos

Code
Shapes
Project Map

to go
t1, forever [fd 1 / 10 seth direction]
forever [clean
         compass, setpos [-195 -79]
         seth direction
         fd 43 bk 43
         settext1 heading]
end



Notes

In this project, we use a second turtle to draw and redraw a line acting as the needle of a compass, so the needle will always point in the direction that the ant is moving.

  1. Hatch a new turtle and name it compass to draw the lines for the needle of the compass.  

  2. Draw a compass shape, or press the "Shapes" button, and copy and paste the compass shape for this project into your project.   You may also place the compass into a shape in the Shapes Center, then place the shape on the compass turtle and stamp it.   This way the center point of the compass turtle will be positioned exactly in the center of the compass, which is where you want it.

    Use drawing tools or a text box to label 4 points on the compass with 0, 90, 180, and 270 degrees.

  3. If your compass turtle now has a compass shape, set it back to a turtle shape.   In the command center, type:
    setsh 0
    and press Enter/Return.

    (If you have drawn your own compass shape, be sure the compass turtle is positioned exactly at the center of the compass.)

  4. In the command center, type:
    pd ht
    and press Enter/Return.
    pd means "pen down" so the turtle will draw as it moves.
    ht means "hide turtle" so the turtle will be invisible.  

  5. Make a text box.   It will have the name text1.  
    Place the eye tool on the text box to open its dialog box.   Click on the check mark next to Show Name to uncheck the mark and hide the name of the text box.   This text box will be used to display the turtle's heading.

  6. In the command center, type:
    freezebg (which means "freeze background")
    and press Enter/Return.   This command means that the background cannot be erased.   We don't want the "grass" or the heading compass to be erased.

  7. In the command center, type:
    show pos
    and press Enter/Return.
    show pos means "show position."   The computer will report two numbers on the next line in the command center, for the compass turtle's x and y coordinates.

  8. In the go procedure, clean erases everything drawn on top of the frozen background.   We only want to erase the line which will be continually redrawn to show the heading of the "ant."  

  9. In this sample, setpos [-195 -79] gives the compass turtle a starting point which is the center of the compass.   Setpos stands for "set position."   The first number is the x coordinate and tells the turtle how far left or right to be.   A negative number is a position to the left of center.   The second number is the y coordinate and tells the turtle how far up or down to be.   A negative number is a position below the center.

    Instead of using these numbers, use the two numbers reported by the computer in the command center for your turtle t2's x and y coordinates.

  10. Fd 43 bk 43 tells the compass turtle to draw a line and move back to its starting position.   As the heading is changed with the direction slider, the old line will be erased with clean just before a new line is drawn.   This gives the effect of a needle which is spinning or turning, but it is really just a line which is continually erased and redrawn in a new position.

  11. Settext1 heading tells the text box named text1 to erase any contents and insert the number which is the turtle's heading (the direction the turtle is facing).   In this procedure, both turtles (t1 and compass) have the same heading.   As the direction slider is moved, the number in the text box continually changes.   If you compare this number to the number on the slider, you will see, for instance, that a heading of -90 is the same as a heading of 270.




What If?
What happens to the number in the text box when you set the direction to -90?
-10? -180?


Challenge
Can you make a compass which is larger or smaller than this one and change the go procedure so that the needle always reaches to the outer edge of the compass circle?


On Your Own - Project Ideas
Use a compass to show the direction as you steer something, such as: a sailboat on a lake, a kite, a ball, a photo or drawing of yourself, word art.





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