Separate speaker notes to accompany presentation on logo:
This presentation uses a version of Logo called StarLogo available through MIT. It can be downloaded for free and installed on your home computer.
In later slides, we will reduce the number of turtles to 1, but for now it is fun to create patterns with 30 turtles!
FD is the command for forward. You follow it with a number that specifies how many steps each turtle should move forward.
Note that the command can be given in upper or lower case.
Note again that the command can be given in upper or lower case. My first command used fd and the next command used FD.
What I have done is used the sequence structure - each turtle followed the first command and then the second command.
Pendown is the PD command and penup is the PU command. Pendown means that the turtles draw as they step. PU means they just move. Notice that when we start the pen is up.
The box on the slide shows the sequence of commands that have been executed so far.
I can save my projects for use in the future.
Note that I can then close the project and later reopen it. To clear the code that I wrote in the Turtle Command Center, I can use Edit/Clear.
I have started a new project here and am moving the turtles and turning them as well. RT means take a right turn RT 90 means turn right 90 degrees.
The turtle command center can be used to control the activity of the turtles. When I want to change the number of turtles and things like that, I switch (using the tabs) to the Observer Command Center. In this example, I then clear the number of turtles and then establish that there will only be one turtle.
When you start a new project, if you do not want the default of 30 turtles, you must set the CT and CRT. I am doing CT and CRT 1 to get one turtle.
I pasted the sequence of commands to give a more readable copy.
To make the picture I made it is important to execute in exactly the same sequence I did. If a step forward or a turn or a color setting were in a different position, the results would be different.
Note the new commands LT for left turn and SETC to set a color. Logo only recognizes the words for standard colors like black, blue, brown, cyan, gray, green, lime, magenta, orange, pink, red, sky, turquoise, white, yellow.
The new command here is BK which means go back. BK 5 means backup 5 steps.
Note here that I too the PU, moved forward and then put the pen down. This can also be done with JUMP (see next slide).
The new command here is JUMP you can see how it works in the example on this slide.
Note that again I have pasted a copy of the commands into the white space for readability.
In this example, I instructed the turtle to create a square. I put the pen down (PD) and then had it go forward 10 and then take a right run of 10 and then go forward 10 and take a right run of 10 until it had created the square.
Note that in all of these where there is only one turtle, the observer control contains CT, CRT1 to clear turtles and then create 1 turtle. When you start a new project, you must set the CT and CRT in the observer control center.
Note also that the default color is red. When I start a new project, the color will get set to red.
The REPEAT command does whatever is enclosed in the square brackets the number of times indicated.
REPEAT 4 means repeat the commands 4 times. The commands are to go forward 10 and then make a right turn of 90. When this is done 4 times, I make a square and end up facing in the same direction as when I started.
In this example I used the repeat to draw the three lines of a triangle and then draw the four lines of a square. See the flowchart on the following page.
This shows the logic of the code shown. I set the color to lime and then I do the code in the loop until I have done it 3 times. Then I turn 180 degrees, set the color to pink and do the code in the next loop until I have done it 4 times.
Now I am back to using thirty turtles (the default). Be careful of the spacing when you type the commands, logo wants spaces as indicated when I typed the command. The syntax is reasonably strict.
The syntax for the if is:
if condition [list of commands]
The condition is COLOR = PINK
I only used one command, FD 10. I could have added other commands which I will do on the next slide.
Now I have the results of executing two IF statements. The second one said if the turtle was yellow, I wanted to put the pen down and then move forward 5 which draws a line.
Finally, I added the IF command that said if the turtle was BLUE, I wanted to move forward 15, put the pen down, make a right turn of 90 and then move forward 5.
This is one of those cases where there is a little flexibility in writing the command. I could have said move forward 15 and then right turn of 90 and then put the pen down before moving forward 5. In other words, it does not matter whether I put the pen down before or after I make the right turn of 90. It does matter that I get the pen down before I go forward 5 or I will not get the effect shown.
The IFELSE has the following syntax:
IFELSE condition [list of commands1] [list of commands2]
Which translates as if the conditions is true execute the list of commands1 which is in the first set of brackets. If the condition is not true execute the list of commands 2 which is in the following set of square brackets. See flowchart on next slide.
If the color is pink step forward 10 else step forward 5.
I have a series of IF statements that are executed in sequence and sent turtles forward and back depending on whether they meet the color specified in the condition.
In this example, if the color is either pink or lime the turtle moves forward 10 else the turtle moves forward 5. See the flowchart on the next slide.
If the color is either pink or lime you want to move forward by 10 steps else you want to move forward by 5 steps.
HT means hide turtle and ST means show turtle
SHOWN? tests to see if the turtle is shown or visible.
Note that I put parenthesis around the whole condition on the first IFELSE and did not put parenthesis around the whole condition on the second IFELSE. They both worked proving that the parentheses are optional.