LOGO Basics

advertisement
1
Logo Basics Using FMS Logo
FMS Logo is available to download at
http://fmslogo.sourceforge.net/
Getting Started
Type FS in the textbox at the very bottom of the FMS Logo window, and click on the
Execute button, or press ENTER.
This will result in the Commander window becoming ‘undocked’ from the drawing
window. The Commander window can be re-sized and repositioned. It is suggested
that you resize it so that it looks something like this:
The triangle in the centre of the drawing window represents a turtle. The turtle can
be moved around the screen by typing various commands in the Commander window.
Summary of the Main Logo Commands
Command
Abbreviation
Notes
FORWARD 50
FD 50
Must have space before distance.
BACK 35
BK 35
Must have space before distance.
LEFT 45
LT 45
Must have space before angle.
RIGHT 45
RT 45
Must have space before angle.
CLEARSCREEN
CS
Clears screen and centres turtle.
HIDETURTLE
HT
Hides the turtle.
SHOWTURTLE
ST
Turtle is visible.
PENUP
PU
Turtle moves without drawing.
PENDOWN
PD
Turtle moves and draws/erases.
PENERASE
PE
Turtle rubs out as it moves.
PENPAINT
PPT
Puts pen down and draws.
HOME
Centres turtle without clearing screen.
Richard English January 2015
2
Using REPEAT
You could draw a square using these commands:
FD 100 RT 90 FD 100 RT 90 FD 100 RT 90 FD 100 RT 90
A quicker alternative is to use the REPEAT command:
REPEAT 4[FD 100 RT 90]
NOTE: There must be a space before the 4 and square brackets must be used.
Writing Procedures
Suppose you wanted to draw the same square several times. You can save time by
defining the instructions as a procedure and calling on this procedure each time you
want to draw the square. You can give the procedure any name of your choice, for
example SQUARE.
To Write and then Run a Simple Procedure
1.
In the Input Box type the word TO, followed by the name of the procedure
e.g. TO SQUARE. Press ENTER.
2.
The following input box will appear.
3.
Type the command REPEAT 4[FD 100 RT 90] and then click on End.
The input box will disappear and the Commander window will display
confirmation that the procedure has been defined.
4.
To run the procedure, type its name (i.e. SQUARE) in the Input Box and then
execute the command.
Richard English January 2015
3
For You to Try
Write procedures which will draw some various 2D shapes, for example:




An equilateral triangle
A square
Other regular polygons (pentagon, hexagon, octagon, decagon etc.)
A circle (or something that looks like a circle)
Give each procedure an appropriate name e.g. ‘HEXAGON’, ‘TRIANGLE’, ‘BIGCIRCLE’,
‘SMALLCIRCLE’ etc.
Something More Challenging ….
Make a note of the angles the turtle has to turn through when drawing various regular
polygons (equilateral triangle, square, pentagon, hexagon, octagon, decagon etc.).
NOTE: This angle is called the exterior angle of the polygon, as opposed to the
interior angle which is the angle inside the polygon, formed by two adjacent sides.
Can you spot a connection between the exterior angle and the number of sides the
polygon has got?
Writing a Procedure which uses another Procedure
A procedure can make use of any other existing procedures that you have written.
The example below assumes that you already have a procedure called SQUARE.
For You to Try
Define the procedure ROTATE by typing TO ROTATE in the Input box and then typing
REPEAT 12[SQUARE RT 30]
and then click on End to complete the procedure.
Clear the screen (CS) and then type ROTATE in the Input box, finally pressing ENTER.
Editing Procedures
You might want to edit a procedure e.g. to change the size of the shape being drawn
or to change an angle, or to change the number of repeats.
To Edit a Procedure
1.
In the Commander window click on the Edall button.
2.
The Editor window will appear, listing the commands in all your procedures.
Richard English January 2015
4
Edit the ROTATE procedure as follows:
Change the number of repeats to 36.
Change the angle to 10 degrees.
3.
From the File menu of the Editor window select Save and Exit.
The Editor window will disappear.
4.
Clear the screen (CS) and then run the procedure i.e. type ROTATE in the
Input Box and then execute the command.
For You to Try
1. Edit some of the procedures you wrote earlier. Try changing some of the
distances or angles or the number of repeats.
2.
Edit the ROTATE procedure so that it rotates shapes other than a square.
Experiment with different numbers of repeats and different amounts of turn.
Can you spot the connection between the number of repeats and the amount of
turn in order to get the turtle back to its starting point?
Changing the Pen Size and Pen Colour
To Change the Pen Colour
1. From the Set menu select PenColor.
2. Select one of the available colours.
3. Click on OK.
To Change the Pen Size
1. From the Set menu select PenSize.
2. Select one of the sizes.
3. Click on OK.
Richard English January 2015
5
Procedures with Parameters
Suppose you want to draw squares of different sizes. This can be done by writing a
procedure with one or more parameters. A parameter is a value which you can vary
each time the procedure is carried out. For example, in the case of a procedure to
draw a square, the length of the side could be a parameter.
Here’s the procedure. It’s called ANYSQUARE and the parameter is called SIDE.
TO ANYSQUARE :SIDE
REPEAT 4[FD :SIDE RT 90]
END
Note that the procedure name must not have already been used already (i.e. use
ANYSQUARE or SQ, but not SQUARE).
Also note that the parameter is always preceded by a colon when defining the
procedure – that’s how FMS Logo knows that it’s a parameter.
Procedures can have more than one parameter.
For You to Try
1.
Define the procedure shown above.
Now type ANYSQUARE 100. The value 100 is substituted into the procedure
in place of the parameter :SIDE.
Try ANYSQUARE 50 or ANYSQUARE 200 etc.
2.
Try defining other procedures with parameters. For example write version of
ROTATE with parameters which will allow you vary the number of repeats and the
amount of turn each time.
Something More Challenging ….
Earlier you wrote separate procedures to draw an equilateral triangle, a square, a
regular pentagon, a regular hexagon and so on. Write a single procedure with
parameters, which will draw regular polygons of any size and with any number of
sides.
One way of doing this is to write a procedure (e.g. POLYGON) with two parameters
(e.g. :SIDES and :ANGLE).
However, if you understand the relationship between the exterior angle and the
number of sides you might be able to write a procedure with just one parameter – the
other value will be worked out automatically within the procedure.
Richard English January 2015
6
To Save Your Procedures
1.
From the File menu select Save As.
2.
The Save As dialogue box should appear. Choose the location where you
want to save the file, type in a file name and finally click on Save.
All of the procedures you have written will be saved as a single file.
These can be loaded and used on a later occasion by selecting Load or Open
from the File menu.
To Save Your Patterns
1.
From the Bitmap menu select Save As.
2.
The Save As dialogue box should appear. Choose the location where you
want to save the file, type in a file name and finally click on Save.
To Print Your Work
1.
From the Bitmap menu select Print.
2.
The Print dialogue box should appear. Click on OK.
Richard English January 2015
Download