Logo
When Logomation starts, a ‘turtle’
at the centre of the screen is waiting to follow your commands.
It can move forward or backward a number of pixels, drawing a
line as it goes. The turtle can also turn (or rotate) left or
right a number of degrees. Nothing is drawn when the turtle rotates,
until the next forward or backward command moves the turtle in
the new direction.
Drawing Commands
Forward xx
move the turtle forward xx pixels (in the direction which it is
facing)
Backward xx
move the turtle back xx pixels
Left xx
turn the turtle to the left xx degrees
Right xx
turn the turtle to the right xx degrees
Up
lift the pen from the paper, no drawing as the turtle moves
Down
lower the pen onto the paper, draw a line as the turtle moves
Width x
set the width of the pen to x pixels
Color r, g, b
sets the pen color (where ‘r’, ‘g’ and
‘b’ are values between 0 and 1)
Clear r, g, b
clears the run window and sets the background color.
With the above commands, draw a box,
a triangle, a 5-pointed star, a house, or whatever.
Note:
Colors on a computer monitor are defined by 3 values, representing
the intensity of the red, green and blue elements which make up
the color. Values must be between 0 (no intensity), and 1 (full
intensity).
eg. 0, 0, 0 -black
1, 1, 1 -white
1, 1, 0 -yellow
0.5, 0.5, 0.5 -mid gray
0.2, 0.2, 0.2 -dark gray etc.
Fill and Repeat
Logomation has no ‘end’
command, but instead uses indented lines of code. These commands
apply to their following indented body statements.
Fill r, g, b
fills the shape defined by the indented movement statements.
Repeat x
repeats the indented statements ‘x’ times.
Re-write your square and triangle programs using the repeat
command. Also, write and investigate ‘star’ and ‘explosion’
programs.
Beautify and
Pause
In the early days of ‘bedroom programming’,
code was often written and de-bugged by one person. Nowadays,
with greater complexity, you will be coding as part of a team.
It is important that others can easily follow, understand and
share your code.
/////////////////////////////////////////////////////////////////////////////////
//
TITLE
//
//
NAME
DATE
//
So, layout your program to aid readability and add comment
statements (//) every few lines to explain what the code does.
It is good practice to use program headers containing your name,
program title, date etc, and also to ‘declare’ any
varibles you use.
These commands are useful for de-bugging,
as they let you see the order in which the turtle goes about its
business.
Pause t
pauses the program for t seconds
Halt
stops the program running
Add pauses to your programs and observe the effect. Simply
‘comment out’ when you need to return to full speed.
Sometimes, coding is easier to read if lines contain more
than one statement. In which case, just seperate each statement
with a semi-colon.
eg. Up; Forward 44;
Down
Logo
Codes 1
Work
out what these following codes produce:
1/
Repeat 4
Forward 40
Left 90
2/
Clear 0, 0, 0
Color 0, 1, 0
Width 2
Left 45
Repeat 4
Forward 60
Right 90
3/
Repeat 2
Forward 50
Right 90
Forward 10
Right 90
Forward 20
Left 90
Forward 30
Left 90
Forward 20
Right 90
Forward 10
Right 90
4/
Repeat 8
Right 90
Forward 20
Left 90
Forward 10
Left 90
Forward 20
Right 90
Forward 10
5/
Repeat 40
Forward 5
Up
Forward 5
Down
6/
Repeat 45
Forward 100
Backward 100
Left 4
7/
Color 1, 0, 0
Width 8
Fill 1, 1, 0
Forward 80
Left 90
Forward 80
8/
Right 45
Repeat 4
Forward 40
Left 90
Forward 40
Left 180
Repeat 2
Forward 40
Right 90
9/
Repeat 8
Left 45
Repeat 2
Forward 80
Left 90
Forward 20
Left 90
10/
Repeat 8
Forward 100
Backward 50
Left 45
11/
Repeat 3
Repeat 5
Forward 60
Left 144
Up
Forward 100
Down
12/
Repeat 36
Forward 10
Left 10
13/
Left 90
Repeat 20
Forward 60
Backward 60
Up
Right 90
Forward 10
Left 90
Down
14/
Varibles
A symbol or name that stands for a value. Variables play
an important role in computer programming because they enable
one program to process different data each time it is run.
In olden days, varibles were assigned to the letters A
to Z, giving a total of 26 varibles, similar to the memory stores
on a calculator. Logomation allows many varibles, called any names
we like.
It is good practice to ‘declare’ and comment
a varible before use.
eg. Score = 0 //players
total points
Whenever we need to add say 150 to the current score, this
can be achieved by:
Score = Score + 150
Spirals &
Slopes
In previous examples, code was fixed with ‘constant’
line lengths. Varibles allow this to be changed to lines
of varying length.
Try out these following codes:
1/
C=0
Repeat 50
Forward C
Print C
Backward C
Left 10
C = C + 5
Pause 0.1
2/
C = 6
Repeat 50
Forward C
Left 90
//try 95 or 120
C = C + 6
Pause 0.1
3/
Up; Backward 200; Down
Left 90
C = 0
Repeat 19
Forward C
// try 100*sin(C)
Print C
Backward C
Right 90
Up; Forward 20; Down
Left 90
C = C + 10
Pause 0.1
Ask (Input)
It’s a little inconvienient to keep altering varibles
within the program, so we can use the Ask() command to allow the
user to input this data.
Ask(X)
where X is the width of
the text field, typically 200
Clear 1,1,0.5
Up; Backward 200; Right 90; Backward
100 //face down page
Print "Program to calculate students
per room."
Forward 36
Print "number of students ?"
Forward 18
Students = ask(200)
Forward 18
Print "number of rooms ?"
Forward 18
Rooms = ask(200)
StudentsPerRoom = Students / Rooms
Forward 18
Print "students in each room =
" . StudentsPerRoom
Write a program to calculate the average value of 3 numbers.
Print (Output)
This prints to the screen, not the printer. The print command
always prints horizontaly, regardless of the turtles angle, at
the current turtle position (even with the pen up). Text within
quotes is printed ‘as is’. A full stop joins or ‘concats’
the phrases together.
eg. Print “Player One =
“ . Score . “points”
will produce: Player One = 0 points
Lesson 3 Functions
Functions are a powerful feature of the Logo language.
They allow the programmer to define their own named functions,
which can be called at any time from the main program. Using functions
enables a complex program to be built up from a number of smaller
routines.
Functions are defined by the function command followed
by a unique name(). They apply to their following indented lines.
eg. You should recognise
the shape this function draws. I’ve named the function ‘square’,
but could have called it anything.
Function Square()
Repeat 4
Forward 44
Left 90
Now I can call the function from the main program.
eg. Repeat 10
Square()
Left 36
Note: Try to make your functions ‘transparent’
by ensuring the turtle finishes the function in the same place
it started. This makes it easier to combine functions together.
Use the above commands to draw a pentagon
and a hexagon. Let ‘n’ represent the number of sides.
Along with the triangle and square
you drew in the last lesson, complete the following table.
Shape
n
Angle
triangle
square
pentagon
hexagon
Can you work out the relationship between
‘n’ and the angle ?
If you can write the angle in terms
of ‘n’, then you can write a program which draws a
polygon for any ‘n’ sides.
Match up the following pairs of commands:
Forward 44
Left 330
Forward -44
Left -30
Left 90
Right 720
Right 30
Backward 44
Left -60
Left 30
Right -720
Right 270
Left 390
Left 720
Right 390
Backward -44
Left 720
Right 60
Write a program that draws a picture,
an icon or your initials, using only vertical and horizontal
lines. Start and finish the turtle
at the centre of your image.
Get_Char(t) wait for key press, or t
seconds, before continuing
|