| How can you write a procedure to show the shape numbers?
This routine shows the number of each shape. Note the line MAKE "X 1 initializes X as 1 and the line MAKE "X :X + 1 increments X by 1. These two make commands are very important to learn and understand. SETSH 5 means set the turtle shape to number 5. There are many shape numbers. |
TO SHOWSHAPE
MAKE "X 1 REPEAT 35 [ SETSH :X WAIT 1 MAKE "X :X + 1 ANNOUNCE :X] END |
| How do I write a procedure that moves the turtle at random?
The key to this procedure is the RANDON NN command. This command generates a random integer from 0 to NN-1. So FD RANDOM 25 will move the turtle forward a random amount from 0 to 24 pixels. What do you change to make the turtle move faster??________ What do you change to make the turtle move more wildly [More angle change?]?_______ |
TO MOVE
FD RANDOM 25 RT RANDOM 50 LT RANDOM 50 END |
| Can the RANDOM NN command be used to probability experiments like flipping a coin?
Logo has a random number generator - RANDOM nn [where nn is one greater than highest integer generated by RANDOM nn. RANDOM 2 yields a 0 or 1 and if 1 = heads then RANDOM 2 acts like a coin flipper. This procedure flips a coin n times. The ANNOUNCE :X creates an alert window with the value of X in it. The procedure uses an IF ... CONDITION ... [ ] statement. If the condition after if is true the commands in the []'s are done. |
TO FLIP :N
MAKE "X 0 REPEAT :N [ IF (RANDOM 2) = 1 [MAKE "X :X + 1]] ANNOUNCE :X END An alert window ![]() |
Write FLIP 100 to flip a coin 100 times.
Note MAKE "X :X + 1 increments X by 1.
How would you increase X by 5?_____________
How do I OUTPUT in Logo?
SHOW :X prints the value of X on the command line
SHOW [Your score is] prints Your score is on the command line
ANNOUNCE :X is to print X in an alert box
SETTEXT1 [Hi There] puts Hi There into text box named text1
SETTEXT1 :X Puts the value of X into Text1
| What are the three buttons at the bottom of the screen?
Command mode, Shape mode, and Paint mode. To use the right click to look at the program box attached to a turtle, you must be in the command mode, not the shape mode See graphics at right. With the Paint mode you can draw on the turtle's play pen or screen! |
![]() Control Mode - Command button down |
![]() Shape Change and Edit Mode |
To stop a program, press <Ctrl><Break> [These are two keys on the key board]. If the action is caused by commands in the turtle's program box, clicking on the turtle starts and stops the program!! Sometimes it is hard to click on a moving turtle - so you use <Ctrl><Break> instead!
| How do you move a specific turtle?
Games usually mean two or more turtles in action at the same time! How do you command a specific turtle? T1, FD 50 tells turtle 1 to move forward 50. All subsequent commands are addressed to turtle 1. T2, RT 59 instructs turtle 2 to turn right 59 degrees. The syntax is name of the turtle, [don't forget the comma] and a pile of commands. Here is a racing procedure where turtle 2 has the advantage. |
TO RACE
T1, FD RANDOM 45 WAIT 1 T2, FD RANDOM 48 WAIT 1 END |
| Turtle 2 is the girl, does she always win a long race?_________ | |
| Can you create a turtle button to set up or start a game?
The user can type commands into the command center like start to begin a race, or you can make a button [turtle] that does the start procedure. Remember clicking on a turtle makes it do its commands in the program box. Clicking a second time on a turtle to make it stop doing its commands. Here I draw a START button for turtle 3 in shape location 43. When you click the start button [or turtle], the race procedure is done many times. The click on the many times button is like a big REPEAT []. |
The program box for turtle 3 which starts the race. |
| How do you tell when two turtles are touching?
There is a reserve word TOUCHING? Name of turtles This line reports when the turtles are intersecting. I added it to the move procedure at right. |
Turtles touching |
TO MOVE
FD RANDOM 25 RT RANDOM 50 LT RANDOM 50 SHOW TOUCHING? "T1 "T2 END |
| The TOUCHING? line in the program generates many falses in the command space, and when the turtles are touching,
the word true is repeatedly printed on the command line.
To generate a message when the turtles touch, use this code. Supposing you wanted to give points for each touch, use the increment line MAKE "X :X + 10 [if there 10 points per touch]. The procedure would look like: |
TO MOVE
FD RANDOM 25 RT RANDOM 50 LT RANDOM 50 IF TOUCHING? "T1 "T2 [MAKE "X :X + 100 SHOW [Your score] SHOW :X ] END |
Your report
Your report should have the procedure to generate what the turtle does and the picture or graphic of what the turtles did.
It is best to copy and paste the procedures into Word Perfect and to capture the graphics with <Print Scrn>,
edit the graphic in Paint Shop and save it as a .wpg file and insert it into your Word Perfect report.
This page is Copyright 2002 by J. Barry DeRoos. All Rights Reserved.
This page may be distributed and used freely, provided that the
copyright notices remain intact.
Last Modified: Nov 18 , 2002.