1 / 25

Using Logo and Logic

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

ghazi
Download Presentation

Using Logo and Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Logo and Logic Please use speaker notes for additional information!

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

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

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

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

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

  7. I did a File/Save Project As and seved the project in a directory/folder I created as movedraw.slogo.

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

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

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

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

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

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

  14. Commands: PD REPEAT 4 [FD 10 RT 90]

  15. SETC LIME PD REPEAT 3 [FD 10 RT 120] RT 180 SETC PINK REPEAT 4 [FD 10 RT 90]

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

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

  18. Commands: IF COLOR = PINK [FD 10] IF COLOR = YELLOW [PD FD 5]

  19. Commands: IF COLOR = PINK [FD 10] IF COLOR = YELLOW [PD FD 5] IF COLOR = BLUE [FD 15 PD RT 90 FD 5]

  20. Command: IFELSE COLOR = PINK [FD 10] [FD 5]

  21. COLOR = PINK YES NO FD 5 FD 10 IFELSE COLOR = PINK [FD 10] [FD 5]

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

  23. IFELSE (COLOR = PINK OR COLOR = LIME) [FD 10] [FD 5]

  24. COLOR = PINK YES NO COLOR = LIME FD 10 YES FD 5 FD 10 IFELSE (COLOR = PINK OR COLOR = LIME) [FD 10] [FD 5]

  25. IFELSE (COLOR = PINK OR COLOR = ORANGE OR COLOR = LIME) [FD 10] [HT] IFELSE COLOR = ORANGE AND SHOWN? [FD 10] [FD 5]

More Related