LOGO

advertisement
LOGO
A SIMPLE COMPUTER LANGUAGE
LOGO Introduction
 http://pages.intnet.mu/jhbpage/Program/Logo/logo.htm
 Logo is the simplest programming language. It was
developed by Seymour Papert in 1968. It was
developed originally as a teaching tool.
 Though Logo is a complete language it is mainly used
for drawing.
The Logo Environment
Basic Logo Commands
Instruction
Shortcut
Description
SHOWTURTLE
ST
Shows the Turtle on the screen
HIDETURTLE
HT
Hides the Turtle from the screen
FORWARDnumber
FD
Moves the Turtle forward according to the number indicated
BACK number
BK
Moves the Turtle back according to the number indicated
RIGHT angle
RT
Changes the direction of the Turtle by turning it to the right
LEFT angle
LT
Changes the direction of the Turtle by turning it to the left
CLEARSCREEN
CS
Erase the picture before a new picture is drawn
How to draw a 100 by 100 square in Logo?
Step 1
FORWARD 100
Step 2
RIGHT 90
How to draw a 100 by 100 square in Logo?
Step 3
FORWARD 100
Step 4
RIGHT 90
How to draw a 100 by 100 square in Logo?
Step 5
FORWARD 100
Step 6
RIGHT 90
How to draw a 100 by 100 square in Logo?
Step 7
FORWARD 100
Step 8
HIDETURTLE
Procedures
A procedure has 3 parts:
1. It must start with the reserved
word “TO”, followed by a one
word procedure name.
2. The main body is made up of
primitives
3. The procedure ends up with
word “END”
A Scalene Triangle
TO scalene
CS
FD 100
RT 150
FD 50
HOME
HT
END
An Isosceles Triangle
TO isosceles
CS
RT 20
FD 100
RT 140
FD 100
HOME
HT
END
A Pentagon
TO pentagon
CS
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
HT
END
Looping
TO pentagon
CS
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
FD 100
RT 72
HT
END TO pentagon
CS
REPEAT 5 [FD 100 RT 72]
HT
END
A Rectangle
TO rectangle
CS
FD 100
RT 90
FD 50
RT 90
FD 100
RT 90
FD 50
RT 90
HT
END
A Rectangle
TO rectangle
CS
FD 100
RT 90
FD 50
RT 90
FD 100
RT 90
FD 50
RT 90
HT
END
TO rectangle
CS
Repeat 2 [
FD 100
RT 90
FD 50
RT 90]
HT
END
An Equilateral Triangle
TO equilateral
CS
FD 100
RT 120
FD 100
RT 120
FD 100
HT
END
TO equilateral
CS
FD 100
REPEAT 2[
RT 120
FD 100]
HT
END
A Kite
TO kite
CS
FD 90
BK 30
RT 90
FD 30
BK 60
LT 45
FD SQRT (2*(30*30))
RT 90
FD SQRT (2*(30*30))
HOME
FD 60
LT 90
FD 30
HOME
END
A Kite
TO kite
CS
FD 90
BK 30
RT 90
FD 30
BK 60
LT 45
FD SQRT (2*(30*30))
RT 90
FD SQRT (2*(30*30))
HOME
FD 60
LT 90
FD 30
HOME
END
Loop and Double Loops
Try each of the following:
(Reset the screen before each try)
1. FD 50 RT 45
2. REPEAT 4 [ FD 50 RT 45 ]
3. REPEAT 8 [ FD 50 RT 45 ]
4. REPEAT 2 [REPEAT 8 [ FD 50 RT 45 ] RT 45]
5. REPEAT 3 [REPEAT 8 [ FD 50 RT 45 ] RT 45]
6. REPEAT 4 [REPEAT 8 [ FD 50 RT 45 ] RT 45]
7. REPEAT 8 [REPEAT 8 [ FD 50 RT 45 ] RT 45]
Double Loops
TO N
REPEAT 8 [REPEAT 8 [ FD 50 RT 45 ] RT 45]
END
Loop
REPEAT 12 [ FD 100 RT 150 ]
Double Loops
REPEAT 72 [ REPEAT 360 [ FD 1 RT 1 ] RT 5 ]
Double Loops
TO C
PERSPECTIVE
REPEAT 4 [REPEAT 4 [FD 100 RT 90] FD 100 DOWN 90
END
Double Loops
TO R
PERSPECTIVE
REPEAT 45 [ REPEAT 360 [ FD 2 RT 2 ] RR 8 ]
END
Basic Logo Commands
Instruction
Shortcut
Description
PU
Pen Up
PD
Pen Down
PPT
Pen Paint
SETXT num1 num2 SETXY
Moves the Position X, Y
Download