fd 10 rt 90

advertisement
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
FD
PD
FD
PU
FD
5
2
2
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.
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.
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.
These commands are
executed in sequence.
If I changed the
sequence, I would get
different results.
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
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
RT
FD
RT
FD
RT
FD
RT
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.
10
90
10
90
10
90
10
90
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
FD 10
RT120
Increase # times
done by 1
FD 10
RT 90
Increase # times
done by 1
RT 180
Set color to pink
Have not
done 4 times
End
Y
SETC LIME
PD
REPEAT 3 [FD 10 RT 120]
RT 180
SETC PINK
REPEAT 4 [FD 10 RT 90]
COMMAND:
IF COLOR = PINK [FD 10]
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.
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]
NO
FD 5
YES
COLOR = PINK
FD 10
IFELSE COLOR = PINK [FD 10] [FD 5]
IFELSE
IFELSE
IFELSE
IFELSE
IFELSE
IFELSE
IFELSE
IFELSE
IFELSE
COLOR
COLOR
COLOR
COLOR
COLOR
COLOR
COLOR
COLOR
COLOR
=
=
=
=
=
=
=
=
=
PINK [FD 10] [FD 5]
YELLOW [FD 15] [FD 2]
BLUE [FD 7] [BK 3]
ORANGE [FD 4] [BK 2]
PINK [FD 10] [FD 2]
LIME [FD 5] [FD 1]
PURPLE [FD 3] [BK 1]
MAGENTA [FD 8] [BK 1]
BROWN [FD 5] [FD 2]
IFELSE (COLOR = PINK OR COLOR = LIME) [FD 10] [FD 5]
NO
YES
COLOR = PINK
FD 10
YES
COLOR = LIME
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]
Download