250 likes | 335 Views
Using Logo and Logic. Please use speaker notes for additional information!. StarLogo starts with 30 turtles on top of each other in the center of the screen (note that the black portion of the screen where the turtles are is somewhat truncated in this slide).
E N D
Using Logo and Logic Please use speaker notes for additional information!
StarLogo starts with 30 turtles on top of each other in the center of the screen (note that the black portion of the screen where the turtles are is somewhat truncated in this slide).
In this example, I keyed in the command fd 5 in the Turtle Command Center. FD 5 means that each of the turtles moves forward 5 steps. Each of the turtles moved out from the center by 5 commands.
I am issuing commands using the sequence structure - one command after another. I have now told the turtles to move forward another 2 steps. The two commands I have issued are: fd 5 FD 2
Commands (SEQUENCE): fd 5 FD 2 PD FD 2 In this example, I used PD for pen down and then told the turtles to take two steps forward. The result are lines drawn by each of the 30 turtles.
Commands: fd 5 FD 2 PD FD 2 PU FD 3 The last two commands I issued lifted up the pen so the turtle does not draw as it moves and then moved the turtles forward 3.
I did a File/Save Project As and seved the project in a directory/folder I created as movedraw.slogo.
Commands: FD 5 PD RT 90 FD 5 When I executed the sequence of commands shown here, I moved each of the turtles forward by 5, then I put the pen down, then I made the turtles all turn right by 90 degrees and then I made each of the turtles step forward 5 in the direction they were now pointing.
Commands: ct crt 1 ct means clear turtles crt means create turtles. must be followed by a number to tell logo how many turtles to create. There are two tabs in the Control Center: one for turtle and one for observer - up until now we have been using the one for turtle. Now I am switching to the one for observer to change the number of turtles.
SETC YELLOW FD 10 PD RT 60 FD 10 RT 90 FD 20 SETC PINK RT 90 FD 15 RT 20 FD 5 RT 10 FD 5 SETC BLUE FD 10 RT 90 FD 10 RT 90 FD 10 LT 90 FD 20 These commands are executed in sequence. If I changed the sequence, I would get different results.
PD SETC ORANGE FD 10 RT 90 BK 5 LT 90 SETC LIME FD 5 LT 90 FD 10 LT 90 PU FD 5 PD FD 5 I pasted a copy of the commands in the white area to show you the commands I used - the actual commands are hard to read.
PD SETC ORANGE FD 10 RT 90 BK 5 LT 90 SETC LIME FD 5 LT 90 FD 10 LT 90 PU FD 5 PD FD 5 JUMP 5 FD 10
Commands: PD FD 10 RT 90 FD 10 RT 90 FD 10 RT 90 FD 10 RT 90 Following this sequence, the turtle draws a square. Notice that I am repeating the sequence FD 10, RT 90. In the next slide I will use a loop to make this happen.
Commands: PD REPEAT 4 [FD 10 RT 90]
SETC LIME PD REPEAT 3 [FD 10 RT 120] RT 180 SETC PINK REPEAT 4 [FD 10 RT 90]
Start Set color to lime Have not done 3 times Y Increase # times done by 1 FD 10 RT120 RT 180 Set color to pink Have not done 4 times Y Increase # times done by 1 FD 10 RT 90 SETC LIME PD REPEAT 3 [FD 10 RT 120] RT 180 SETC PINK REPEAT 4 [FD 10 RT 90] End
I am using the default of 3 0 turtles and I only want the ones that are PINK to move forward. The code here is checking to see if the color is equal to PINK. If it is those turtles and only those turtles will move forward 10 steps. Note that the FD10 must be enclosed in square brackets because the syntax of logo requires it. COMMAND: IF COLOR = PINK [FD 10]
Commands: IF COLOR = PINK [FD 10] IF COLOR = YELLOW [PD FD 5]
Commands: IF COLOR = PINK [FD 10] IF COLOR = YELLOW [PD FD 5] IF COLOR = BLUE [FD 15 PD RT 90 FD 5]
Command: IFELSE COLOR = PINK [FD 10] [FD 5]
COLOR = PINK YES NO FD 5 FD 10 IFELSE COLOR = PINK [FD 10] [FD 5]
IFELSE COLOR = PINK [FD 10] [FD 5] IFELSE COLOR = YELLOW [FD 15] [FD 2] IFELSE COLOR = BLUE [FD 7] [BK 3] IFELSE COLOR = ORANGE [FD 4] [BK 2] IFELSE COLOR = PINK [FD 10] [FD 2] IFELSE COLOR = LIME [FD 5] [FD 1] IFELSE COLOR = PURPLE [FD 3] [BK 1] IFELSE COLOR = MAGENTA [FD 8] [BK 1] IFELSE COLOR = BROWN [FD 5] [FD 2]
COLOR = PINK YES NO COLOR = LIME FD 10 YES FD 5 FD 10 IFELSE (COLOR = PINK OR COLOR = LIME) [FD 10] [FD 5]
IFELSE (COLOR = PINK OR COLOR = ORANGE OR COLOR = LIME) [FD 10] [HT] IFELSE COLOR = ORANGE AND SHOWN? [FD 10] [FD 5]