You are on page 1of 9

MswLogo - Introductory Worksheet

Copyright © by Mark Baker 1997 Copyright waiver Return to MarkChrisSoft home page

The Commander
This allows instructions to be entered and executed immediately. Type your instructions into the input box, then press return. There is a triangular pointer on the main MswLogo screen, this is called the turtle (for historical reasons)! The turtle obeys the commands or instructions, that you type into the Commander. This is an artistic turtle and it is holding a pen, so that when it moves, a line is drawn on the screen. To repeat an instruction entered earlier, click on it in the window above the input box (the output box), then press return. Alternatively, you can double click on the item. Press the Status button to see what Logo is doing at any time. Press the No Status button to close the status window.

Simple Drawing
forward, back right, left pen up pen down arc home clearscreen Moves the pen forwards/backwards, eg. forward 100 moves the pen forward 100 units Turn right/left e.g. right 90 means turn right 90 degrees Picks up the pen so that it is above the screen Puts the pen down on the screen Draws an arc. arc 360 50 draws a full circle, of radius 50. arc 180 50 draws a semi-circle of radius 50. Returns the turtle to its starting position Clears the screen (rubs everything out) and returns the turtle to its starting (home) position

Note: Spaces are important. forward100 is illegal, forward 100 is legal right90 is illegal, right 90 is legal 1. Click on the input box and type in these instructions. Draw a sketch in your books to show the shape that is drawn: forward 100 right 90 forward 50

left 20 forward 100 right 20 back 100 home 2. What do these instructions draw? Draw a sketch of it in your books. What do these instructions draw? fd 120 lt 90 pu fd 50 lt 90 pd fd 120 pu home For each of the questions below. arc 360 50 pu fd 50 pd arc 360 50 Abbreviate Commands These programs take a lot of typing. then write the instructions into your book. forward. left pen up pen down clearscreen fd / bk rt / lt pu pd cs 4. back right. draw the shape on the screen first. so Logo allows you to use abbreviations for some of the most common commands. . forward 120 left 90 forward 50 left 90 forward 120 left 90 forward 50 3. What do these instructions draw? Draw a sketch of it in your books.

Write down the instruction that will draw a circle. Write down the instructions that will draw a square. Write down the instructions that will draw a triangle. 7. 6. 8.5. with sides of length 100 (see diagram below). Write the correct instructions in your book. of radius 50. Write down the instructions that will draw these shapes. Repeat Structure . Enter them on the computer and debug (correct) them. with sides of length 80.

Logo allows you to write procedures which are useful sets of instructions. Enter it on the computer to test that it works. A parameter is a value that you send into a procedure and you can use a parameter to change the size of the square that is drawn. 10. Write a procedure in your book that will draw a rectangle. Draw a hexagon (six-sided shape) using the repeat instruction. to draw a shape of your own choice.g. Sending Parameters The DrawSquare procedure is very useful. when drawing a square you would need: fd 50. What shape do these instructions draw? repeat 8 [fd 40 rt 45] 11. e. Type in these instructions. Write the instructions that you used in your book. fd 50. 15. fd 50. . rt 90. so long as you always want to draw a square where all the sides are 100 units long. Write the instructions that you used in your book. rt 90. You could draw the square using these instructions: repeat 4 [fd 50 rt 90] Everything inside the bracket is done four times. Write the instructions that you used in your book. rectangles and so on. squares. rt 90. Often you would be repeating the same basic shapes. which will create the procedure DrawSquare: to DrawSquare repeat 4 [fd 100 rt 90] end Now enter the instruction "DrawSquare" (this is known as "calling the procedure") and explain what happens. 12. fd 50. Procedures Using Logo to draw a complicated picture would take a long time. rt 90 To make this easier you can use a loop structure (or repetition structure) to repeat the same instructions as many times as you like. It is no good if you want to draw squares of different sizes. Try to draw a square using the repeat instruction. the length of the sides. 13. Write the instructions into your book and draw a sketch to show what happens when you call your procedure.Often you want to repeat the same instructions several times. 14. It would be much more useful if you could vary (change) the size of the square. Write another procedure. Draw a rectangle using the repeat instruction. For the square procedure we want one parameter. 9. You can then call them up whenever you want to.

22. 19. Use this procedure to draw some shapes. eg. Anything that comes after the semi-colon is ignored by the program and is just there as a programmer's comment. Sketch the design that these three commands draw. Explain what the procedure POLYGON does. Other colours include: [0 255 0] green [0 0 255] blue [128 128 128] grey . all of them a different size. Comments You should always try and put helpful comments in your programs. Enter these commands: DrawSquare2 50 DrawSquare2 75 DrawSquare2 100 18. Enter this procedure: to polygon :length :sides repeat :sides [FD :length RT 360.to DrawSquare2 :length repeat 4 [fd :length rt 90] end 16. 17. so that other people can understand what you have done.1] setpencolor[255 0 0] Sets the width of the line drawn to 10 units Sets the width back to normal again Sets the colour of the pen to red. 24. Enter this procedure.0/:sides] end 23. You can do this in Logo by typing a semi-colon. FD 100 . Use this procedure to draw four shapes. to Draw :length repeat 3 [FD :length RT 120] end 20.this moves you forward 100 units Changing Pen Attributes (Properties) setpensize[10 10] setpensize[1. Enter this procedure. using different numbers for length and sides. What shape does it draw? 21.

y] (must use penup if you do not want a line drawn from your current position) Return to MarkChrisSoft home page Author: Mark Baker. Add some comments to your program. Explain what bugs you found in your program and what you had to do to correct them. e-mail mbaker@rmplc. all numbers from 0-255. to explain what you have done. Additional Commands Here are some additional commands that you might like to experiment with. 28. where r = amount of red. Create your own picture or design.[0 0 0] black setpencolor [r g b] The general case. using Logo. 29. 30. Enter the commands on the computer and correct any errors (bugs) in your program. 27. 26. Draw a sketch of your picture/design in your book and write down the commands that you think you will need. g = amount of green and b = amount of blue. Your Own Picture 25. Print out the finished program and glue it into your book.co. You should try and use some of the procedures that you have already entered. hideturtle setpos[x. showturtle. using different pen colours and different line widths. You might want to write some new procedures too.uk Last revision: 24th May 1997 .

com Term 1 Class activities . The turtle's pen can be lifted and lowered.http://www. FD 20 PENUP FD 20 PENDOWN FD 20 PENUP FD 20 PENDOWN FD 20 . . . REPEAT 4 [FD 100 LEFT 90] The command "FD 100 LEFT 90" is executed four times. drawing a line and moving lifting the pen so it won't draw anything not drawing but moving lowering the pen so it draws again drawing a line and moving [edit] Loops There are three loop (repeat) commands. giving spectacular results with little effort. . REPEAT 36[ RT 10 REPEAT 360 [FD 1 RT 1]] [edit] Defining procedures. thus drawing a rudimentary dotted line. Loops may be embedded. This draws a box.softronix. the need for an editor Basic Chair . . REPEAT is one.Logo commands The pen Turtle drawing a dotted Line The analogy of a turtle with a pen attached to its tail is often used. An approximation of a circle can be constructed easily with 360 small rotations and a step forward: REPEAT 360 [FD 1 RIGHT 1].

any time CHAIR is entered. procedures may be written over many lines. for example. It passes the information 'by value' and the colon is pronounced as 'the value of'. using the TO END pair: TO CHAIR REPEAT 4 [FD 100 RT 90] FD 200 END However. Internally procedures are words and in this case. Now any future FD movements will erase anything beneath them. REPEAT 4 [CHAIR] would repeat the CHAIR operation four times. The procedure. except that in the former a line is deposited on the display device and in the latter a line is removed.(to enter the editor mode. usually by EDALL. All Logos can invoke an Editor. the turtle can be set to erase using the command PENERASE (PE). and the turtle's pen must erase. EDALL . EDALL . Animations require both the ability to draw shapes and to erase shapes. (word) is instructed to expect something and give that something a name.Procedures can be defined on the command line. [edit] Animation Logo was designed in spirit of "low threshold and no ceiling. The pen can be restored with the command PENPAINT (PPT). and return information." that enables easy entry by novices and yet meet the needs of high powered users. then the actual procedure) TO ERASECHAIR PE BK 200 REPEAT 4 [FD 100 RT 90] PPT END CS CHAIR WAIT 200 ERASECHAIR A WAIT delay between the drawing and the erasing introduces the illusion of motion. CS REPEAT 20 [CHAIR WAIT 200 ERASECHAIR FD 20] Logo can pass extra information to its words. The word CHAIR can be used as a command. In UCBLogo. EDALL TO CHAIR REPEAT 4 [FD 100 RT 90] END FD 200 The new word is saved into the available vocabulary. the sequence REPEAT 4 [FD 100 LEFT 90] FD 200 will be executed. Using the turtle analogy. but the definition will be lost once the Logo session is over. the interpreter understands 'FD the value of 200'. the turtle's pen must paint. The process is the same. as nothing is interpreted until the edit is complete. The colon is used for this purpose. then the actual procedure) TO CHAIR :thesize REPEAT 4 [FD :thesize RT 90] FD :thesize FD :thesize . In the editor. the procedure is limited to the physical line length of the input device. When the procedure is run with a command like CHAIR 200. the word :thesize takes the value 200 so when FD :thesize is executed.(to enter the editor mode.

END CS REPEAT 9 [CHAIR 50 RT 20 CHAIR 100 WAIT 50 RT 20] .