d56979b3d600f9b0c35e427fbf2584fe.ppt
- Количество слайдов: 53
B. A. (Mahayana Studies) 000 -209 Introduction to Computer Science November 2005 - March 2006 12. Logo (Part 1) An introduction to Logo: drawing, moving, turning, repetition, and basic procedures. n 000 -209 Intro to CS. 12/logo 1
Overview n n n 1. What is Logo? 2. Installing Logo 3. Basic Commands 4. Drawing a Square 5. More Commands 6. The Repeat Command continued 000 -209 Intro to CS. 12/logo 1 2
n n n 7. Procedures 8. Circle and Square 9. Drawing a Triangle 10. Drawing a House 11. Drawing a Checkboard 12. MSW Logo Examples 000 -209 Intro to CS. 12/logo 1 3
1. What is Logo? n A programming language developed at the MIT Artificial Intelligence Lab 4 MIT = Massachusetts Institute of Technology n Logo is easy to learn, but powerful. n Logo has been used in telecommunications, multimedia, and robotics. 000 -209 Intro to CS. 12/logo 1 4
2. Installing Logo n We're using MSW Logo, but there are many other Logo systems. MSW Logo Website: 4 http: //www. softronix. com/logo. html n The set-up kit (Windows installer: ( 4 http: //www. softronix. com/download/mswlogo 65. exe n Tutorials 4 The Great Logo Adventure http: //www. softronix. com/download/tgla. zip 4 An Introduction to MSW Logo http: //www. southwest. com. au/~jfuller/logotut/menu. htm continued 000 -209 Intro to CS. 12/logo 1 5
n Double click on mswlogo 65. exe to start the installation. n The program will be added to the start menu as "Microsoft Windows Logo. " 4 called n MSW Logo The MSWLogo directory contains an Examples/ folder (see end of these slides. ( 000 -209 Intro to CS. 12/logo 1 6
MSW Logo in Action menus the turtle status window editor turtle drawing area command window command box command input window 000 -209 Intro to CS. 12/logo 1 7
What is the Turtle? n Originally, the turtle was a robot that moved around the floor when the user typed Logo commands into a computer. n Today, it is a picture on the Logo drawing area 4 in 000 -209 Intro to CS. 12/logo 1 MSW Logo, the turtle is drawn as a triangle 8
3. Basic Commands n forward <number < 4 the larger the number the farther the turtle will go 4 if you use a large enough number, the turtle will walk off the screen and wrap around to the other side 4 e. g. forward 40 n back <number < 4 the turtle will move backwards 4 e. g. back 33 continued 000 -209 Intro to CS. 12/logo 1 9
n right <number < 4 the number is how many degrees the turtle will turn right 4 e. g. RIGHT 90 l n turn the turtle to the right by 90 degrees. left <number < 4 turns 000 -209 Intro to CS. 12/logo 1 the turtle to the left 10
4. Drawing a Square type these commands into the command input window , pressing <enter> after each command forward 100 right 90 forward 100 000 -209 Intro to CS. 12/logo 1 11
Error Messages n Your input: forward 10 20 n Your input: back error messages 000 -209 Intro to CS. 12/logo 1 12
5. More Commands n penup 4 causes the turtle to pick up its pen so that when it moves no line is drawn n pendown 4 puts the pen back down so drawing starts again continued 000 -209 Intro to CS. 12/logo 1 13
n setpencolor <number < 4 changes the colour of the turtle’s pen 4 e. g. setpencolor 5 l make your turtle draw a pink line MSW Logo has command help under "Index " continued 000 -209 Intro to CS. 12/logo 1 14
n clean 4 clears n the turtle's drawing area home 4 moves 000 -209 Intro to CS. 12/logo 1 the turtle back to the center of the drawing area 15
Example Using Setpencolor forward 100 setpencolor 5 right 72 forward 100 setpencolor 14 right 72 forward 100 setpencolor 3 right 72 forward 100 setpencolor 2 right 72 forward 100 000 -209 Intro to CS. 12/logo 1 Because the turtle turned right 72 degrees 5 times, it made a pentagon 16
6. The Repeat Command n n Get the turtle to do things many times, by using the repeat command. e. g. repeat 4 [forward 10[ 4 move the turtle forward 10 spaces, 4 times 4 the turtle will move forward 40 spaces altogether n In general, you type: 4 repeat 000 -209 Intro to CS. 12/logo 1 <number> [ <commands[ < 17
Draw a Square with Repeat repeat 4 [forward 100 right 90[ 000 -209 Intro to CS. 12/logo 1 18
Using Repeat n . 1 What will the following command draw ? 4 repeat n 3 [forward 100 left 120[ . 2 Make a circle using the repeat command. 000 -209 Intro to CS. 12/logo 1 19
Answer 1: Draw a Triangle repeat 3 [forward 100 left 120[ 000 -209 Intro to CS. 12/logo 1 20
Answer 2: Draw a Circle repeat 360 [forward 1 right 1[ 000 -209 Intro to CS. 12/logo 1 21
7. Procedures n Add a new command to Logo by writing a procedure. 4 to <name of your procedure> <command 1> A procedure is a new <command 2> command, built out of : other commands end continued 000 -209 Intro to CS. 12/logo 1 22
n For example : 4 to square repeat 4 [forward 100 right 90] end n The new command (procedure) is for drawing a square 4 it 000 -209 Intro to CS. 12/logo 1 can be used just like other Logo commands 23
Typing in a Procedure • A "To Mode" window pops up after you type to <name of procedure < • You enter your procedure line by line, and type end or press Cancel to finish. continued 000 -209 Intro to CS. 12/logo 1 24
• After typing repeat 4 [forward 100 right 90] end continued 000 -209 Intro to CS. 12/logo 1 25
n Executing the procedure: 4 square 000 -209 Intro to CS. 12/logo 1 26
A Circle Procedure n The program : 4 to circle repeat 360 [forward 2 right 1] end n Test it out : 4 circle 000 -209 Intro to CS. 12/logo 1 27
The Edall Button n To add more procedures, or change one you've already written, click on the Edall button. 000 -209 Intro to CS. 12/logo 1 28
Using Edall n Enter a procedure for drawing a purple pentagon: 4 to pentagon setpencolor 10 repeat 5 [forward 75 right 72] end n In the Editor "File" menu, select "Save and Exit" when you are finished. 000 -209 Intro to CS. 12/logo 1 29
A Pentagon 000 -209 Intro to CS. 12/logo 1 30
Saving Procedures n If want to use the procedures some other time, you should save them. 000 -209 Intro to CS. 12/logo 1 31
8. Circle and Square n How would you write the procedure circle_and_square to make a drawing that looks like this? n The triangle is the position of the turtle at the end of the procedure. 000 -209 Intro to CS. 12/logo 1 32
Procedure 4 to circle_and_square home clean repeat 360 [forward 2 right 1] forward 50 repeat 3 [left 90 forward 100] left 90 forward 50 end n Now change circle_and_square so it uses the circle procedure. continued 000 -209 Intro to CS. 12/logo 1 33
A procedure calls another procedure. circle_and_square calls circle 000 -209 Intro to CS. 12/logo 1 34
9. Drawing a Triangle n We want a procedure that draws a triangle with a flat base. start n This requires different turnings of the turtle: 120 30 90 000 -209 Intro to CS. 12/logo 1 120 35
000 -209 Intro to CS. 12/logo 1 36
10. Drawing a House n A simple house is a square with a triangle on top of it. n After drawing the square, the turtle must move to the start of the triangle. n After drawing the triangle, the turtle must move back to its original position. 000 -209 Intro to CS. 12/logo 1 37
000 -209 Intro to CS. 12/logo 1 38
Procedure Calls square house calls triangle 000 -209 Intro to CS. 12/logo 1 39
11. Drawing a Checkboard n We're going to write a series of procedures that help us make a checkboard. n A checkboard is a series of columns. A column is a series of squares. A square is made from 4 corners. n n 000 -209 Intro to CS. 12/logo 1 40
Procedure Calls n I'll write four procedures, that call each other in a chain. checkboard 000 -209 Intro to CS. 12/logo 1 calls column square corner 41
Drawing a Corner n We want a procedure that draws a straight line, then turns 90 degrees to the right. n to corner forward 20 right 90 end 000 -209 Intro to CS. 12/logo 1 42
Where did the Turtle Go? n hideturtle 4 make the turtle invisible 4 drawing still occurs, but with no turtle n showturtle 4 makes 000 -209 Intro to CS. 12/logo 1 the turtle visible again 43
Drawing a Square with Corners n A square is four calls to corner: 000 -209 Intro to CS. 12/logo 1 44
Drawing a Column with Squares n A column is eight squares, followed by the turtle moving back to its starting position. n After drawing a square, the turtle needs to move up by 20 to get to the starting position for the next square. start continued 000 -209 Intro to CS. 12/logo 1 45
000 -209 Intro to CS. 12/logo 1 46
Drawing a Checkboard with Columns n A Checkboard is eight columns. n After drawing a column, the turtle must move right to the starting position for the next column. n At the end of drawing the checkboard, the turtle should move back to the lower-left corner of the checkboard. 000 -209 Intro to CS. 12/logo 1 47
000 -209 Intro to CS. 12/logo 1 48
12. MSW Logo Examples/Misc/curves. lgo 000 -209 Intro to CS. 12/logo 1 continued 49
Examples/3 D/Hilbert. lgo continued 000 -209 Intro to CS. 12/logo 1 50
Examples/3 D/solar. lgo continued 000 -209 Intro to CS. 12/logo 1 51
Examples/Misc/clock. lgo continued 000 -209 Intro to CS. 12/logo 1 52
Examples/Windows/calc. lgo 000 -209 Intro to CS. 12/logo 1 53
d56979b3d600f9b0c35e427fbf2584fe.ppt