Turtle Fun LOGO For The Spectrum 48K

You might also like

You are on page 1of 101

Turtle Fun:

LOGO for the Spectrum 48K


Other Macmillan books of related interest

Advanced Graphics with the IBM Personal Computer Ian O. Angell


Advanced Graphics with the Acorn Electron Ian O. Angell and Brian J. Jones
Advanced Graphics with the BBC Model B Microcomputer
Ian O. Angell and Brian J. Jones
Advanced Graphics with the Sinclair ZX Spectrum
Ian O. Angell and Brian J. Jones
Interfacing the BBC Microcomputer Brian Bannister and Michael Whitehead
Assembly Language Programming for the Acorn Electron Ian Birnbaum
Assembly Language Programming for the BBC Microcomputer (second edition) Ian
Birnbaum
Advanced Programming for the 16K ZX81 Mike Costello
Using Your Home Computer (Practical Projects for the Micro Owner)
Garth W. P. Davies
Micro-Maths Keith Devlin
The Purple Planet: Micro-PROLOG for the Spectrum 48K
Serafim Gascoigne
Microchild - Learning through LOGO Serafim Gascoigne
Using CP/M Peter Gosling
Beginning BASIC Peter Gosling
Continuing BASIC Peter Gosling
Practical BASIC Programming Peter Gosling
Program Your Microcomputer in BASIC Peter Gosling
A Science Teacher's Companion to the BBC Microcomputer
Philip Hawthorne
The Sinclair ZX81- Programming for Real Applications
Randle Hurley
More Real Applicationsfor the ZX81 and ZX Spectrum
Randle Hurley
Programming in Z80 Assembly Language Roger Hutty
Beginning BASIC with the ZX Spectrum Judith Miller
The Commodore 64 in Action: Sound, Graphics and Filing
M. M. Novak
Using Sound and Speech on the BBC Microcomputer
Martin Phillips
A Beginner's Guide to Interfacing the BBC Microcomputer
Martin Phillips
File Handling on the BBC Microcomputer Brian J. Townsend
Computer Literacy: A beginners' guide Vincent Walsh
Good BASIC Programming on the BBC Microcomputer
Margaret White
Mastering Data Processing J. Bingham
Mastering Computer Programming P. E. Gosling
Mastering Pascal Programming E. Huggins
Mastering COBOL R. Hutty
Mastering Computers G. G. L. Wright
Turtle Fun
LOGO for the Spectrum 48K

Serafim Gascoigne

M
MACMILLAN
© Serafim Gascoigne 1985

All rights reserved. No reproduction , copy or transmission of this


publication may be made without written permission.

No paragraph of this publication may be reproduced, copied or


transmitted save with written permission or in accordance with the
provisions of the Copyright Act 1956 (as amended).

Any person who does any unauthorised act in relation to this


publication may be liable to criminal prosecution and civil claims for
damages.

First published 1985


Published by
MACMILLAN EDUCA nON LTD
Houndmills, Basingstoke, Hampshire RG21 2XS
and London
Companies and representatives throughout the world

Typeset by Communi type Leicester

British Library Cataloguing in Publication Data

Gascoigne, Serafim
Turtle Fun : LOGO for the Spectrum 48K
1. Sinclair ZX Spectrum (Computer-Programming)
2. LOGO (Computer program language)
001 64' 24 QA 76.8 S625

ISBN 978-1-349-08242-1 ISBN 978-1-349-08240-7 (eBook)


DOI 10.1007/978-1-349-08240-7
Contents

Preface Vll
Acknowledgement Vlll

PART 1: TURTLE FUN

Section 1 Introducing LOGO 3


Section 2 How to move the turtle 6
Section 3 Walkabout 9
Section 4 Writing a procedure 11
Section 5 Some turtle terms 16
Section 6 Outer space 27
Section 7 Pretty poly 34
Section 8 Spirolaterals 42
Section 9 Looking at circles 47
Section 10 Pot-pourri 53
Section 11 The LOGO mouse 60

PART 2: WORD FUN 65

Section 12 Looking at lists 66


Section 13 The Postcard Machine 71
Section 14 Autopoet 74
Section 15 Master Mind 76
Section 16 Adventure games 79

Index 92

v
Preface

The world of microcomputers is forever changing. There is always


something new to learn and find out. How can you keep up? Will you
be able to program the computers of the future? And what about
'intelligent' machines and robots, especially the LOGO turtle?
This book will help you to keep up with events by introducing you to
a very powerful control language of the future, called LOGO. LOGO
has in fact been developed by computer scientists working in a new
science called Artificial Intelligence. LOGO has been written for young
programmers. It comes from another language called LISP, which is
one of the main languages used to control 'intelligent' computers and
robots. Using such commands as STARTROBOT or REPEAT
[FO R WARD 50 LEFT 120] for example, you can either drive a small
mechanical device called the floor turtle or control the screen turtle, a
movable cursor on your TV screen. You can also teach the turtle your
own commands, called 'procedures', which can include graphics, text
and sound.
Learning LOGO will not only teach you another computer language
but it will also help you to organise your thinking and ideas in a clear
and structured way. Apart from the scientific value oflearning LOGO,
it is fun! The world of the LOGO turtle is an exciting and intriguing
world that ranges from simple screen doodling to the study of turtle
geometry - a new geometry, totally different from school geometry but
surprisingly familiar!
LOGO allows you to invent your own language, to be creative and
above all, to make your programming a personal venture.

vii
Acknowledgement

My thanks to my wife, Sarah-Frances, for the illustrations and the


circle patterns in section 9.

viii
PART 1
TURTLE FUN

1
Section 1

Introducing LOGO

What is LOGO?

LOGO is a language that enables you to create your own personal


ideas at the keyboard. It allows you to explore and be inventive. You
can use LOGO to write stories and quiz games, create a database, or
draw fascinating shapes. You can also use LOGO as a calculator.

A personal language

LOGO is very much a personal language. There is no right or wrong


way of using LOGO. You can use the language how you like. It
depends entirely on what you want to do with it. This does not mean
that your programs will work if they contain mistakes, nor will you be
able to use, for instance, commands or procedures that LOGO does
not understand. But you can make up your own words and teach the
computer to understand them.
As for mistakes, or 'bugs' as we call them in computing - well they
are a normal feature of programming.
3
4 Turtle Fun: LOGO for the Spectrum 48K

----------~-~~~~----
Making friends

LOGO can also be a shared experience. Unless you live on a remote


island or in the depths of the Amazon jungle, LOGO is a good way of
making friends. It's great fun to be able to discuss your discoveries and
ideas with other LOGO enthusiasts. I personally can't wait to show
somebody else what I have done or to find out what other people are up
to!

An ideas book

This book has been especially written as a companion to the User


Manual supplied with the LOGO package from Sinclair. It is an ideas
book based on the experience of young, and in some cases not-so
young, LOGO users. If you are a complete beginner, it is best to work
through each section of the book slowly and carefully until you
understand how LOGO works.
As you work through the sections you will in fact meet some
advanced ideas, which at first you may not understand. Don't worry;
one of the best ways to learn LOGO is to use it. Run some of the
advanced programs and see what they do. What you may not
understand in the beginning may become clearer as you write your own
programs and start using LOGO for your own purposes.
If you already have some experience of LOGO then dig about a bit
and pick out what interests you. You can begin where you like.
Introducing LOGO 5

Types of LOGO

Although this book is written especially for the Sinclair Spectrum, the
ideas are the same for any computer that uses LOGO. LOGO is a fairly
standard language and the version used here can be used with Tandy,
Apple, Commodore, Terrapin, Atari, Amstrad, IBM and BBC com-
puters. If your machine has a different kind of LOGO, it does not
necessarily mean that you cannot use this book. The syntax (use of
words) may need modifying, the ideas do not.
Section 2

How to move the turtle

Before you begin to explore the ideas in this book, you will need to
know how to use some basic commands. If you already know how to
move the turtle, you may skip this section.
Having loaded your program as described in the User Manual, you
are ready to begin. To call up the turtle, you type Showturtle (ST). You
will now see a turtle or cursor-shape at the centre of the screen. This is
the LOGO screen turtle.
To move the turtle you use the following commands

FORWARD RIGHT
BACK LEFT

These commands can be shortened to FD (FORWARD), BK


(BACK), RT (RIGHT) and LT (LEFT). Most LOGO commands that
you will meet in this book can in fact be shortened.
Typing FORWARD 10 or FD 10 (and pressing ENTER) will move
the turtle forward ten steps on the screen, and FOR WARD 20 or FD
20 (press ENTER) will move the turtle forward twenty steps.
Typing BACK 10 or BK 10 (press ENTER) will move the turtle
backwards ten steps, and so on.
Try changing the number of steps after the commands, FO RW ARD
and BACK.
To turn the turtle to the left you type: LEFT followed by a number.
6
How to move the turtle 7

FD 25 BK 25 LT 90

FD 10 RT 90 FD 10

This is the number of degrees. For example LEFT 90 or LT 90 (press


ENTER) will turn the turtle to the left 90 degrees. (If you are not sure
what a degree is, it is a unit of measurement like miles or litres. Degrees
are used to measure angles just as miles are used to measure distance or
litres are used to measure quantities of liquid.)
RIGHT 90 or RT 90 (press ENTER) will turn the turtle to the right
90 degrees. LEFT 1 or LT 1 will turn the turtle to the left I degree.
RIGHT 45 or RT 45 will turn the turtle to the right 45 degrees.
Try changing the number of degrees after the commands, LEFT and
RIGHT. Don't forget to press ENTER whenever you want the
computer to carry out your commands.
As the turtle moves, you will have noticed that it draws a line. If you
wish, you can move the turtle without drawing a line by typing PENUP
or PU. When you wish to resume drawing, type PENDOWN or PD.
You can also hide the turtle as it draws by typing HIDETURTLE.
To make the turtle reappear simply type SHOWTURTLE.
8 Turtle Fun: LOGO for the Spectrum 48K

The basic commands so far are

FORWARD BACK RIGHT


PENUP PENDOWN LEFT
HIDETURTLE SHOWTURTLE

One of the important things to do with LOGO is to experiment! Try


out these commands and see what happens. Some important ideas
have been discovered by people doodling on the screen. From the very
moment that you start moving the turtle, you are ready to discover new
ideas. See what you can find.
Section 3

Walkabout

This section is about screen doodling. How you do it, and what you do,
is up to you. But you might like to play around with the following
ideas.

SETBG REPEAT
SErpC RANDOM
PU RT HT LOGO words
PD LT ST
FD BK WAIT

Take some of the LOGO words in the box and explore. You will have
to do a bit of research for yourself. For example, you will need to look
up the LOGO words in the user manual.
Remember SETBG and SETPC need inputs such as I for blue, 2 for
red .. .
What about RANDOM? This word chooses your inputs at random.
It is like throwing dice - any number can come up, well almost any
number.
Try

9
10 Turtle Fun: LOGO for the Spectrum 48K

REPEAT lO [FD RANDOM 50 LT RANDOM 50]

How many different ways can you use RANDOM? Can you for
example use RANDOM to change the colours on the screen?

REPEA T 50 [SETBG RANDOM 6....... ]

Have you ever held a mirror up to another mirror? If you haven't, have
a go! If you have, then the next program may remind you of what
happens.
SETBG 1 SETPC 7
REPEA T 5 [L T 45 PU FD 30 PD REPEAT 5 [RT
72 REPEAT 5 [FD 20 LT 72]]]
Section 4

Writing a procedure

In section 3, the REPEAT command produced an interesting pattern


made up of pentagons. To complete this pattern you have to retype the
commands again. This involves more work for you. There is however
an alternative - teach the computer to do it.

Teaching the computer

Let's write a program or procedure to draw the complete pattern.


But first you need to call it something, and you need to tell the
computer that you want it to learn something new. To do this you type
the LOGO word TO followed by the name of the procedure (program).
Let's call the pattern CRYSTALS.
Type TO CRYSTALS and press ENTER. The LOGO symbol>
appears at the beginning of the next line. The computer does not
appear to do anything; it is in fact waiting for you to give it some more
commands. You can now type

SETBG 1 SETPC 7
REPEA T 5 [LT 45 PU FD 30 PO REPEAT 5 [RT 72
REPEAT 5 [FD 20 L T 72]]]
END

Now press ENTER and wait. After a few seconds the message

CRYSTALS defined
11
12 Turtle Fun : LOGO for the Spectrum 48K

should appear on the screen. Now for the big moment. Type
CRYSTALS and sit back. Provided that you have typed the commands
correctly, you should have the pattern shown below.

You have taught the computer a new word called CR YST ALS. Let's
teach it some more.

D
TO GREGORY
REPEA T 4 [FD 50 RT 90]
END

TO LOUISE
REPEAT 3 [FD 60 LT 120]
END
L
The procedures CRYSTALS, GREGORY and LOUISE are now
words that the computer understands in the same way that it
understands FD, BK, LT and RT etc.
You can now use these new words to create other procedures and so
on.

TO PATTERN
GREGORY
LT 45
GREGORY
LT 45
LOUISE
Writing a procedure 13

Inside the procedure PATTERN, we have used the procedures


GREGORY and LOUISE as subprocedures to the new procedure
PATTERN. Perhaps you would like to finish PATTERN yourself.

Note You can use capital letters such as TO CR YSTALS or you can use
small letters such as - to crystals. It's up to you which you use. You
can 't, however, mix small and capital letters.

More doodles

Your doodling can produce some spectacular results if you use what is
called recursion. Recursion is the ability of a procedure to call itself.
Let's take a few commands

L T 46 FD 50 RT 11 0 FD 20 LT 46 FD 10
(press ENTER)

Now repeat these commands to draw a shape

REPEA T 10 [L T 46 FD 50 RT 110 FD 20 LT 46
FD 10]

The result on the screen is not very interesting. Let's omit the REPEAT
10 and use recursion instead. For this we will need to write a procedure.

TO DOODLE
L T 46 FD 50 R T 110 FD 20 LT 46 FD 10

Now tell the procedure to call itself by putting the name of the
procedure DOODLE in the next line. The final procedure looks like
this

TO DOODLE
L T 46 FD 50 RT 110 FD 20 LT 46 FD 10
DOODLE
END
14 Turtle Fun: LOGO for the Spectrum 48K

I think you'll agree that this is a considerable improvement. But how


do you stop it? You can't! To stop a recursive procedure you have to
write in a line that tells the procedure to stop. You can stop it physically
when you have had enough by pressing CAPS and BREAK.
Here are some more recursive procedures

TO STARBURST TO STAIRS
SETBG 6 SETPC 2 FD 20 RT 90
FD 100 FD 20 LT 90
BK 120 STAIRS
RT 21 END
LT65
STARBURST
END

TO TWIRLS
FD 7
REPEA T 8 [FD 4 RT 45]
TWIRLS
END

Play around with the use of recursion yourself. Type any commands
you can think of and see what happens.

Using subprocedures

We can use any procedure as a subprocedure (see PATTERN). For


example we can put TWIRLS inside another procedure called
TWIRLSl.
Writing a procedure 15

TO TWIRLS}
TWIRLS
LT 80
TWIRLS}
END

To run TWIRLS} you will have to delete the recursive line in the
subprocedure TWIRLS, otherwise you won't be able to get out of the
subprocedure. You can fill your procedures with subprocedures like
building blocks.
What happens if you put all the procedures together? Nothing!
Unless you remember to delete the recursive line in each individual
procedure, you will find that the turtle is trapped inside the first
subprocedure!

TOTHE.LOT
STARBURST
STAIRS
TWIRLS
THE. LOT
END

This new procedure will not work until you have removed all the
recursive lines in each individual subprocedure.
Section 5

Some turtle terms

Objects OUTPUT
Primitives Variables
Brackets and Parentheses

Objects

As well as using numbers as inputs to your procedures, you can use a


word or a list. These are known as objects. For example

TO COLOURS :X TO TEAM.A :MEMBERS


PR:X PR :MEMBERS
END END

The input for COLOURS could be either a word or a list. You could
type, for example, COLOURS "RED or COLOURS [RED BLUE
GREEN] . Note that a single word is preceded by quotation marks (").
Numbers could also be preceded by quotation marks, but in practice
we do not use them in this case. For TEAM.A we can type TEAM.A
[Anatoly Jason Beryl Floella].
If you are using words (as opposed to lists), the words themselves can
be made from letters or figures , or a combination of both. You can also
use symbols

TO ALIEN. LANGUAGE :X
PR:X
END
16
Some turtle terms 17

Instead of using letters, you could use symbols to make your word or
list of words.
Try typing ALIEN. LANGUAGE followed by the word £*/-.

ALIEN. LANGUAGE "£*/-

Remember all LOGO words must begin with (").


Here are some more examples of LOGO objects used as inputs to
procedures.

Objects as lists

TO GARDEN :VEG
PR:VEG
END

Type GARDEN [BEANS ONIONS CARROTS]

TO ALIEN. LANGUAGE :X
PR:X
END

Type ALIEN. LANGUAGE [££?* ?*/< »*?]

TO NEWS :ITEM
PR [TODA Y'S NEWS IS ]
PR :ITEM
END

Type NEWS [BRITAIN WINS 5 GOLD MEDALS]

Objects as words

TO ANIMAL :NAME TO TOWN :NAME


PR :NAME PR :NAME
END END
18 Turtle Fun: LOGO for the Spectrum 48K

Type ANIMAL "MONKEY

Type TOWN "SHIPLEY

Primitives

Primitive means an in-built LOGO command or operator such as FD


or REPEAT. The names of your own variables and procedures,
although part of LOGO's vocabulary, are not primitives. They do not
come ready-made with the language but are created by you, the
programmer.

Brackets and Parentheses

Brackets [ ] are used to form a list

[Milk Butter Eggs]


[FD 100 LT 122]

Parentheses ( ) allow you to use more than two inputs with certain
LOGO primitives

PR (SE [What's your name] "my "friend)

Variables

We are surrounded by variables, although we may not always be aware


of them! In school, you are sometimes asked to find the answer to a
number sentence such as

x + 5 = 20

that is, something plus five equals twenty. The 'something' represented
by x is called a variable.
Again we read in the newspaper "Mr X leaves a million pounds to
local cats' home". Who is Mr X?
At the supermarket you are asked by a smiling TV celebrity which
Some turtle terms 19

margarine tastes creamier. Brand X or Brand Y? Here, two variables X


and Yare being used.
In LOGO variables are made in two ways.

1. By writing them in the TO statement

TO SQUARE :SIZE

The variable in this statement is :SIZE .

2. By writing them after the LOGO word MAKE

MAKE "SIZE 60

The variable in this example is "SIZE .

But why use :SIZE and "SIZE? The (") before SIZE represents the
name of this variable, while the (:) before SIZE gives you the value of
the variable.
When you use MAKE with ("), you are creating a LOGO word.

MAKE "SIZE 60

This tells LOGO to create a word called "SIZE which has the value 60.
Now, whenever you type PRINT :SIZE, you get the answer 60, which is
the value of "SIZE.
PRINT :SIZE therefore tells LOGO to print the value of "SIZE.

TO PATTERN
MAKE "SIZE 60
FD :SIZE RT 73
PATTERN
END

The command FD in PATTERN moves the turtle forward :SIZE


which has the value 60 steps.
Another way to obtain the same pattern on the screen is to write

TO PATTERN :SIZE
FD :SIZE RT 73
PA TTERN :SIZE
END
20 Turtle Fun: LOGO for the Spectrum 48K

This time the input is not fixed (for example, 60 steps), but can be given
any value. By typing PATTERN 60, the same pattern is produced. But
if you type PATTERN 70, :SIZE now has the value 70.
Remember

"SIZE means the name of the variable.


:SIZE means the value of the variable.

This does not only apply to numbers

MAKE "FRUIT "PLUM


PR :FRUIT
>PLUM

The value of "FRUIT is "PLUM, which is printed without the (").

MAKE "FLOWERS [ROSE DAISY TULIP]


PR :FLOWERS
>ROSE DAISY TULIP

Again the value of "FLOWERS is the list [ROSE DAISY TULIP]

MAKE "ROB. ROY 7.5


PR :ROB.ROY
> 7.5
The value of any variable can be obtained by using (:) before the name.

The cockerel and the eagle

When you create a variable using TO, this variable only belongs to the
procedure in which it appears. Thus in

TO TRI :SIDE
Some turtle terms 21

:SIDE only belongs to the procedure TRI. It is a local variable, a 'stick


in the mud' that never leaves its own procedure. If you write another
procedure

TO TRIANGLE :SIDE

the :SIDE of TRIANGLE is not the same as the :SIDE of TRI. All
variables are separate and totally exclusive to their own procedures.
You cannot transfer, swap or exchange them. They are local. The
:SIDE of TRI is local - it is only interested in its own procedure. The
:SIDE of TRIANGLE behaves in exactly the same way. They may look
the same on paper, but in practice they are not.
However when you use MAKE to create a variable such as

MAKE "FRED 22

the value of FRED is stored in the computer's general memory. From


now on, whenever you use :FRED to find its value (which is 22), this
value remains constant and appears in all your procedures that use
:FRED. The variable :FRED is a global, that is, universal variable. The
whole world is its playground. But what has this got to do with
cockerels and eagles?
A global variable is like the eagle that flew over seas, forests and
mountains, while a local variable is like the cockerel who never went
further than the farmyard. As far as the cockerel was concerned,
nothing existed outside its own farmyard (procedure).

TO F ARMY ARD :ANIMAL


PR :ANIMAL
END

Let's give :ANIMAL the value COCKEREL. To do this we type

FARMYARD "COCKEREL

The output on the screen is COCKEREL.


:ANIMAL is like the cockerel in the story. It only belongs to the
procedure FARMYARD. But if you use MAKE "ANIMAL as in the
new procedure WORLD
22 Turtle Fun: LOGO for the Spectrum 48K

TO WORLD
MAKE "ANIMAL "EAGLE
PR :ANIMAL
END

the :ANIMAL of WORLD belongs to all procedures that make use of


this variable.

TO FOREST TO MOUNTAINS TO SEAS


PR :ANIMAL PR :ANIMAL PR :ANIMAL
END END END

the value of :ANIMAL is now EAGLE for WORLD, FOREST and


MOUNTAINS; and if you run the procedure FARMYARD, you will
find that the eagle has landed there as well!

Using one or two variables

You can use any word you like to make a variable. You cannot,
however, use a LOGO primitive, which is a word that is part of
LOGO's basic vocabulary.
Here are a few procedures that either use one or two variables.

TO ASTRA :SIZE
REPEAT 5 [FD :SIZE L T 144]
END

TO SPANGLE :ANGLE
FD 30
RT:ANGLE
SPANGLE :ANGLE
END

TO STARTREK :SPOCK :BONES


FD :SPOCK
LT :BONES
STARTREK :SPOCK - 10 :BONES
END
Some turtle terms 23

Setting a random variable

TO MILKY. WAY
MAKE "ANS RANDOM 150
REPEAT 5 [FD :ANS RT 144]
PU MOVE PD
MILKY. WAY
END

What does this program do? Nothing, until you have defined the
subprocedure MOVE.

TO MOVE
FD RANDOM 100 RT RANDOM 360
END

?•

Now what does it do?


We can also be more precise in our use of RANDOM by combining
it with a fixed input

FD 50 + RANDOM 15

This tells the turtle to move forward a random number of steps


between 50 and 50+ 15; that is, we tell the turtle to choose any number
between 50 and 65. In the previous procedure MOVE, the turtle chose a
number from 0 to 100

FD RANDOM 100

But this time we are asking the turtle to limit its choice to between 50
and 65.
24 Turtle Fun : LOGO for the Spectrum 48K

Here is another example

RT 90 + RANDOM 20

This time we are asking the turtle to choose a number between 90 and
110. Instead of choosing a random number of steps, the turtle is
choosing a random number of degrees . We can go on to redefine
MOVE as MOVEl.

TO MOVEI
REPEAT 20 [FD 50 + RANDOM 15 RT 45 +
RANDOM 90]
END

In MOVEI the turtle goes forward between 50 and 65 steps and turns
RT between 45 and 135. Try this new subprocedure MOVEI with
MILKY. WAY and compare the result with the use of MOVE as a
subprocedure.

OUTPUT

To understand the use of OUTPUT, let's see it in action.

TO MESSAGE
OP [I LOVE LOGO]
END

Type PRINT MESSAGE.


OP in the procedure MESSAGE means store [I LOVE LOGO] until
required. It can be retrieved by the command PRINT or by another
procedure, for example

TO PAGE
REPEAT 4 [PRINT MESSAGE]
END

OP can be used within some quite sophisticated procedures.

TO NAMES
MAKE "ANS RANDOM 3
Some turtle terms 25

IF :ANS = 0 [OP "CELIA]


IF :ANS = I [OP "MALCOLM]
IF :ANS = 2 [OP "HAROLD]
END

Don't worry about the use of IF for the moment. It will be explained at
the end of this section.
Again

TO PAGEl
PR SE [MY NAME IS] NAMES
PR SE [MY NAME IS] NAMES
PR SE [MY NAME IS] NAMES
END

SE is short for SENTENCE. It is used to combine a number of lists to


make one big list . In PAGEl it combines the list MY NAME IS with
the value of NAMES, to give such sentences as

MY NAME IS CELIA
or
MY NAME IS HAROLD

Your own DOODLE MODE

If you have a younger brother or sister, you might like to program


some of the keys so that they can draw on the screen, by simply pressing
one key at a time.

READCHAR LOGO words


IF

To program the keys you will need two new LOGO words. These are
IF and READCHAR. IF is used with conditional statements. That
means that you can use IF followed by certain conditions. In the
language of logic we can say: if something is true then do so and so,
otherwise do something different. Let's look at the main procedure to
see how IF works.
26 Turtle Fun: LOGO for the Spectrum 48K

TO PLAY
MAKE "REPLY READCHAR
IF :REPL Y = "F [FD 10]
IF :REPL Y = "B [BK 10]
IF :REPL Y = "R [RT 45]
IF :REPL Y = "L [LT 45]
PLAY
END

You can of course add other commands to this program, which can
include your own procedures. For the moment however let us look at
what the procedure PLAY does.

TO PLA Y - this sets up the computer MAKE "REPLY READCHAR


-this makes a certain key do something, that is, read a character.
IF :REPL Y = "F [FD 10] - if the key that you press is the F key then
move the turtle 10 steps.
IF :REPL Y = "B [BK 10] - if you press the B key then move the turtle
backwards 10 steps and so on.
The word PLAY at the end of the program is recursive. It tells the
computer to go back to the beginning and start again. If you omit the
second PLAY, you only get one go. Try leaving it out and see what
happens.
Experiment with the procedure PLAYas much as you like. Try
changing the word "REPLY and :REPL Y to "BANANAS and
:BANANAS or use "PERSON-PRESSES and :PERSON-PRESSES.
You can add other commands, such as CLEARSCREEN (CS), or
HOME, or the name of a procedure you have written. And if you are
feeling really ambitious, you could program all the keys to do
something.
Section 6

Outer space

You can use your turtle like a space shuttle to explore outer space. You
can launch it off the screen into an invisible world where it will
continue to carry out your commands. How does it do this? The turtle's
range is much greater than the size of your TV screen. The turtle can
move up to 32767 steps in any direction from the centre of your screen.
Normally if you give the turtle a large forward or backward input, it
will disappear off the screen to reappear on the opposite side. This is
called 'wrap around'. It's rather like tying a parcel with a very large
piece of string. The turtle's trail, like a piece of string, is wrapped round
and round the screen. But unlike a piece of string for tying a parcel, the
turtle and its trail can also disappear, like the famous Indian rope trick,
into thin air!
The turtle does not really disappear but continues to draw out of
sight. What you see on your screen in fact is only a small portion of the
turtle's world.
To allow the turtle to escape from your screen you need the LOGO
27
28 Turtle Fun: LOGO for the Spectrum 48K

word - WINDOW. Type WINDOW followed by FD 600 and press


ENTER. Where is the turtle now? Can you bring it back?

You have opened the window and allowed the turtle to crawl freely
into outer space. To prevent the turtle from disappearing all you have
to do is close the window by typing WRAP or FENCE. (I will leave you
to find out what is the difference between WRAP and FENCE. See if
you can find out without looking up the answer in the User Manual.)
The launching ofthe turtle into outer space can also be controlled by
other LOGO words called operators

I SETHEADING TOWARDS POSITION I


The SETHEADING operator turns the turtle so that it is facing in
the direction of the position you have requested. When the turtle is in
the home position, the heading of the turtle is 0, that is, facing up the
screen.
TOWARDS tells you which way the turtle should be facing in order
to reach a certain point on the screen. To land the turtle at the centre of
the screen, we would need to know in which direction to send the turtle.
Let's assume that the turtle is off the screen somewhere in outer space.
To bring the turtle back to the centre of the screen we can use the
following procedure called FIND. This procedure not only finds the
turtle but also tells us in which direction to send it.

TO FIND
OP TOWARDS [00]
END

In this procedure OP in the second line outputs the heading required by


the turtle if it is to set off for home, the position of which is [0 0].
Outer space 29

In Sinclair LOGO the centre ofthe screen is always 0 O. We can now


type

PRINT FIND

and the answer on the screen will tell us in which direction to head the
turtle towards home . You can, of course, head the turtle towards any
position in the turtle's world .
We can play with this idea by writing another procedure FIND 1
which uses FIND as a subprocedure and SETHEADING (SETH).

TO FINDI
REPEAT 4 [FD 20 RT RANDOM 360]
SETH FIND
FD 100
END
This procedure sends the turtle randomly around the screen, then sets
the turtle's heading towards the centre of the screen by using the
subprocedure FIND. The turtle is then sent FD 100. In FIND, OP
stores the answer to the operator TOWARDS until it is required .
We can extend this idea further by a more advanced procedure
which uses a conditional statement.

TO FIND2
IF FIND < 180 [MOVE] [HT]
END
If the direction indicated by TOWARDS is less than 180 run the
procedure MOVE, otherwise HIDETURTLE. An alternative to HT
could be another procedure or command.
The operator POSITION tells you where the turtle is at any time on
or off the screen. The answer, or output, is given as two numbers . If you
type

PRINT POS
when the turtle is in the home position the answer will be 0 O. Move the
turtle about on the screen and use PRINT POS to find out where it is.
Using these operators together with the command WINDOW, you
can now launch your turtle into outer space. Here is a game that you
can play with your friends .
30 Turtle Fun: LOGO for the Spectrum 48K

Turtle launch

Send your turtle into outer space and then bring it gently back to earth.

FD 3000

PRINT TOWARDS [0 0]

This asks the turtle what heading it requires to aim back for home. The
required heading appears on the screen. It could be

263.04738

for example. Now enter

SETHEADING 263.04738

and REPEAT many times [FD 2]. Press ENTER and you will see a
perfect re-entry, and if you get it right a perfect landing as well. You can
also play this game by writing a procedure.

TO LAUNCH
FD 5000
RT 180
REPEA T 250 [FD 20]
END
Outer space 31

You can also use SETHEADING and TOWARDS together.

TO LOOK
RT 80 - RANDOM 180 FD 5
SETH TOWARDS [0 0]
LOOK
END
o

SOUND effects

To produce sound in your procedures use the LOGO word SOUND


followed by the duration and the pitch. The duration is how long the
note lasts. It is measured in seconds. The pitch is the height of the note,
given in semi-tones. The duration is between 0 and 255. The pitch is
between -62 and 75.

SOUND [duration pitch]

for example

SOUND [0. 1-18]

Team members

LOGO word MEMBERP

The LOGO word MEMBERP is used to check whether a certain item


belongs to a list. If it does, take such and such action .
The best way to understand how MEMBERP is used is to see it in
action!
32 Turtle Fun: LOGO for the Spectrum 48K

TO NUMS:Z
TS
IF MEMBERP 3 :Z [PR [TRUE]] [PR [FALSE]]
END

Now enter

NUMS [357]

The answer will be TRUE since 3 does belong to the list :Z which
consists of the numbers [3 5 7].
But if you enter

NUMS [456]

the answer will be FALSE. The number 3 does not in this example
belong to the list [4 5 6].

A simple database

One of the obvious uses of MEMBERP is for questioning a database.


Let's say that you have a database that contains information about
some hockey teams. We want to find out whether Bob plays for Team
1. You do not want to print out all the teams so you ask

PR MEMBERP "BOB :TEAM 1

Before you can ask this question you must have information about
Team 1 in the database.

MAKE "TEAMl [JIM DIANE CHAS MATT]


END

Now you can ask the question again.

PR MEMBERP "BOB :TEAM 1

What is the answer?


Outer space 33
Number machine

Here is an idea you might be able to use for your own programs.

TO MACHINE :Z :COUNT
TS
IF MEMBERP :COUNT:Z [PR [EUREKA!]] PR
:COUNT]
MACHINE :Z :COUNT + 1
END

To start the print out on your screen you enter

MACHINE [357] 10
Section 7

Pretty Poly

You may have enjoyed drawing polygons at school using a ruler and
pencil. Even if you did not enjoy drawing them, using the turtle to draw
polygons can be an exciting experience. The power of the turtle allows
you to produce some spectacular effects at the press of a button.
Figures that would require hours of precision drawing with a pencil
can be produced on the screen instantly.
Here is a simple procedure to get you started. You can draw
polygons of all shapes and sizes. The procedure, which I have called
POL Y, is as follows

TO POLY :SIZE :ANGLE


FD :SIZE
LT :ANGLE
POLY :SIZE :ANGLE
END

By typing POL Y, followed by an input for the sides and an input for the
angle, you can produce some amazing figures on the screen. The last
line in the procedure is recursive. It tells the turtle to start again.
34
Pretty poly 35
Try
POLY 1090

POLY 60144

POLY 30108

POLY 50 160

You might like to experiment with the ANGLE input. Can you make
any predictions as to what kind of shape the turtle will produce? How
many sides will it have? How many points or vertices? Will the lines
cross each other?

POL Y with subprocedures

You can also use subprocedures inside the POLY procedure. Instead of
FD, for example, use the name of a procedure such as TRIANGLE or
SQUARE.
To demonstrate this, let's write a new version of POLY and call it
POLYI

TO POL Yl :SIZE :ANGLE


TRIANGLE :SIZE
RT :ANGLE
POL Yl :SIZE :ANGLE
END

If you have not already got a procedure called TRIANGLE, here is one
for you to experiment with.

TO TRIANGLE :SIZE
REPEAT 3 [FD :SIZE RT 120]
END

You can of course invent your own program to draw a triangle. Try

POLYI 60 144
36 Turtle Fun: LOGO for the Spectrum 48K
Polyspirals

From the simple POL Y procedure you can go on to produce what are
called polyspirals. For this let's create a new procedure and call it
POLYSPI.

TO POLYSPI :SIZE :ANGLE


FD :SIZE
LT:ANGLE
POL YSPI :SIZE + 3 :ANGLE
END

This new procedure is really the POLY procedure again . However the
last line

POLYSPI :SIZE + 3 :ANGLE


tells the turtle to increase the size of the figure by 3 each time. The
increase in size is written in the last line, which also uses recursion to
repeat POL YSPI.
You can go a stage further and make the increase in size (called an
increment) a variable as well. Let's call it INC.

TO POLYSPIl :SIZE :ANGLE :INC


FD :SIZE
LT :ANGLE
POL YSPI 1 :SIZE + :INC :ANGLE :INC
END

This procedure allows you to choose the increment or increase in step


each time. However the increment remains the same throughout the
procedure. It is the :SIZE that gets bigger. Note that in the last line of
this procedure :INC has to be written twice! POL YSPIl needs three
inputs. The combination :SIZE + :INC is regarded as one input for
:SIZE. Therefore :INC is written again in the same line.
The next procedure, called POL YSPI2, makes the increment grow
this time in proportion to :SIZE.

TO POL YSPI2 :SIZE :ANGLE


FD :SIZE
LT :ANGLE
Pretty poly 37
POL YSPI2 :SIZE + :SIZE/lO :ANGLE
END

Here you can see that the increment is not written as a variable but is
included in the variable :SIZE. In the recursion line I have written

:SIZE + :SIZE/IO

This simply means, add the value of :SIZE to :SIZE divided by 10.
You can carry out any arithmetical operations you like on inputs.
For example, you can use +, -, * and I. (* is used for multiply and 1 is
used for divide.) Have a go at using different operators inside your
procedures. Here are just a few examples.

:SIZE * 4 (multiplication)
FD :SIZEI2 (division)
FD :SIZE + 10 (addition)

You can even use operators with the inputs to your procedures. You
can type, for example

POLYSPI23360/7

where you are asking the turtle to divide the angle of 360 degrees by 7.
Here is another program that uses BK as well as FD and uses + and 1
as operators.

TO POL YSPI3 :SIZE :ANGLE :INC


WINDOW SETBG 1 SETPC 3
FD :SIZE SETPC 7 FD 20 + :SIZE/2
BK :SIZE/2 RT :ANGLE
POL YSPI3 :SIZE + :INC :ANGLE :INC
END

I have used some cosmetics here! You can set your own background
and pencolour. As you can see, the size inputs are divided by 2, except
in the last line.
38 Turtle Fun: LOGO for the Spectrum 48K

Here is a list of inputs that you might like to try

POLYSPI3 20 162 5

20 160 1

20 119 3

3 110 3

721

3 75

3 360/7 2

The last example divides the angle input by 7.


Pretty poly 39

Stopping your procedures

You will have noticed that POLY and POLYSPI do not stop. This is
because we have used recursion. To stop a procedure that is recursive
you need a conditional statement.

IF :SIZE > 100 [STOP]

This tells the turtle to stop if the size of the figure is greater than 100.
This conditional statement using IF can be used with any procedure in
which you are using recursion.

Using RANDOM

Here is another poly program that uses random.

TO RANDP :SIZE :ANGLE :INC


MAKE HANS RANDOM 10
IF :ANS = 0 [PD] [PU]
FD :SIZE LT :ANGLE
RANDP :SIZE + :INC :ANGLE :INC
END

The conditional statement in this procedure tells the turtle to pendown


if the random number is O. If not, then penup.

The inspiral

So far we have experimented with the size of polyspirals. But what


about changing the angle? Can you apply the same ideas of increment
and arithmetical operators to the angle input in the POL YSPI
procedures?
40 Turtle Fun: LOGO for the Spectrum 48K

TO INSPI :SIZE :ANGLE


FD :SIZE
RT :ANGLE
INSPI :SIZE :ANGLE + 10
END

Try running this procedure. What kind of figure does it produce?


What about this one?

TO INSPII :SIZE :ANGLE :INC


FD :SIZE
LT :ANGLE
INSPIl :SIZE :ANGLE + :INC :INC
END

And this one?

TO INSPI2 :SIZE :ANGLE :DEC


FD :SIZE
RT :ANGLE
INSPI2 :SIZE :ANGLE - :DEC :DEC
END

What does :DEC stand for? What does this procedure do? Could you
think up your own name for :DEC?

More spirals

Instead of the POLYSPI procedure you can also draw spirals by using
variables with REPEAT and a MAKE statement. Here are two
examples for you to try

MAKE "SPIRAL 1
REPEAT 250 [FD :SPIRAL RT 71 MAKE "SPIRAL
:SPIRAL + 3]

In the first example we use the variable called SPIRAL for the number
of steps that the turtle moves forward . This is followed by another
MAKE statement that tells the turtle to increase its steps by 3 each
time. All the commands inside the brackets are repeated 250 times.
Pretty poly 41

MAKE "SPIRO 0
REPEA T 100 [FD 10 RT :SPIRO MAKE "SPIRO
:SPIRO + 10]

This time it is the angle that changes. The variable SPIRO for the angle
is also followed by another MAKE statement that tells the turtle to
increase the number of degrees by 10. These commands are repeated
100 times. What kind of shape do these commands produce?

Passing the buck

To complete this section on spirals, here is a curious program that


draws a spiral that is shared between two procedures. Where does it
begin? Where does it end?

TO RED.BUCK
MAKE "SIZE :SIZE +1
FD :SIZE L T 45
BLUE.BUCK
END

TO BLUE.BUCK
FD :SIZE RT 90
IF :SIZE > 100 [STOP]
RED .BUCK
END
Section 8

Spirolaterals

Turtle trip
- -- - "'-
"\
In this section we will explore a new order of patterns called \
spirolaterals. Consider this line of commands
\
FD 10 RT 90 FD 20 RT 90 FD 30 RT 90

Nothing in itself, but let's put this line inside a procedure and use
recursion as well .

TO TRIP
FD 10 RT 90 FD 20 RT 90 FD 30 RT 90
TRIP
END

We are off to a promising start!


Let's now write a new procedure with a variable called :ANGLE
42
Spiro/atera/s 43

TO TRIPI :ANGLE
FD 10 RT :ANGLE FD 20 RT :ANGLE FD 30 RT
:ANGLE
TRIPI :ANGLE

Try these inputs

TRIPI 120 150 168


176 36

Try some for yourself. Try some spirolaterals with more than 3 steps.
How can we get the turtle to stop when it has completed or closed the
shape on the screen? Does the turtle in fact always produce a closed
shape? Explore for yourself and see if the turtle draws a closed shape
every time.
44 Turtle Fun: LOGO for the Spectrum 48K

Use your heading!

TO TRIP2 :ANGLE
FD 10 RT :ANGLE FD 20 RT :ANGLE FD 30 RT
:ANGLE
IF HEADING = 0 [STOP]
TRIP2 :ANGLE
END

Try these inputs 100, 45, 72, 80.

Varying the length

In the next procedure we have not only varied the angle but the length
as well. We have also used a maximum of 4 steps.
TO TRIP3 :LENGTH :ANGLE
FD :LENGTH RT :ANGLE FD :LENGTH * 2 RT
:ANGLE FD :LENGTH * 3 RT :ANGLE FD
:LENGTH * 4 RT :ANGLE
IF HEADING = 0 [STOP]
TRIP3 :LENGTH :ANGLE
END
The procedures TRIP, TRIPI, and TRIP2 are called order-3 spiro-
laterals, since there is a sequence or pattern of 3 steps each time. TRIP3
is an order-4 spiro lateral. Try TRIP3 5 116 and 20 168

Turtle travel

Not only can you vary the length and the angle but you can also choose
the numbers of the steps, the order of the spirolateral, by using an
additional variable. Let's call this variable MAX. You no longer need
to type in all the steps, you can just include them in the variable MAX.

TO TRAVEL :COUNT :LENGTH :ANGLE :MAX


IF :COUNT > :MAX [RESET]
FD :LENGTH * :COUNT RT :ANGLE
TRA VEL :COUNT + 1 :LENGTH :ANGLE :MAX
END
You will also need a subprocedure which can be called RESET. This
resets the counting mechanism of TRA VEL to 1 each time.
Spiro/atera/s 45
TO RESET
MAKE "COUNT 1
END
If you do not make COUNT 1, what do you get instead?
Sometimes you can get caught out by heading = O. TRAVEL 3 4412
is an example. This procedure stops too early. To overcome this you
will need to insert an extra line

IF AND :COUNT = :MAX HEADING = 0 [STOP]

This means in ordinary English, if COUNT is the same as MAX and


the HEADING is zero then stop the procedure. You do not want the
turtle to check its heading until it has completed the FD with the
maximum length.
TO TRA VEL 1 :NUMS :COUNT :LENGTH :ANGLE :MAX
IF :COUNT> :MAX [RESEll
IF AND :COUNT = :MAX HEADING = 0 [STOP]
IF MEMBERP :COUNT :NUMS [FD :LENGTH * :COUNT
LT :ANGLE] [FD :LENGTH * :COUNT RT :ANGLE]
TRAVELI :NUMS :COUNT+ 1 :LENGTH :ANGLE :MAX
END
Here are some inputs for TRAVEL 1

[3 5 7] 1 10 100 3
[1 2] 1 10 135 11
[2] 1 10 120 11
[3 4 7] 1 5 120 11
[3 4 6 7] 1 5 120 11
[4 8] 1 10 90 8
46 Turtle Fun: LOGO for the Spectrum 48K
Section 9

Looking at circles

How many ways can you draw a circle? You can use a pencil and a
compass. You can use a dinner plate, a coin or a dustbin lid. You can
use a piece of string that is tied to a stick in the ground. This method of
drawing circles is used to mark out sports pitches etc. If you are
familiar with coordinate geometry, then you will know that you can
draw a circle by plotting points on a grid and then join them together to
produce a circular graph. Another way to draw a circle is to repeat a
number of defined movements or use recursion.
This method of drawing a circle is unique to the turtle, or is it? You
can trace the outline of a circle by walking it yourself. But what do you
do? Can you talk yourself through the procedure for a circle. Can you
describe in simple turtle commands what you are doing?
Turtle geometry

Drawing circles with the turtle is part of a new geometry called turtle or
differential geometry. I wonder what the famous mathematician Isaac
Newton would have done, had he had a LOGO turtle? Perhaps you
could find out about Newton and think of ways he might have used
LOGO.
Drawing a circle by recursion.

TO CIRCLE
FD 5 RT 10
CIRCLE
END

47
48 Turtle Fun: LOGO for the Spectrum 48K

The immediate problem with this procedure for drawing a circle is that
the turtle does not stop! To stop the procedure you need an extra line.

IF HEADING = 0 [STOP]

How many units does it take to make a full circle, that is before the
turtle stops? You can count the number of units by putting in aWAIT
command.

TO CIRCLEl
WAIT 20
FD 5...

How many degrees has the turtle turned?

Using variables

TO CIRCLE2 :SIDE :ANGLE


FD :SIDE RT :ANGLE
IF HEADING = 0 [STOP]
CIRCLE2 :SIDE :ANGLE
END

Does the turtle always go through the same number of degrees to


complete a circle? The total turning of the turtle is called the Total
Turtle Trip or TTT for short.

Drawing a circle using REPEAT

Find your favourite circle and repeat the number of units that the turtle
used to draw your circle. For example

TO CIRCLE3
REPEAT (units) [FD ? LT?]
END

My favourite circle is

TO CIRCLE4 :SIDE
REPEA T 36 [FD :SIDE RT 10]
END
Looking at circles 49

By drawing your own circles you may have discovered that the turtle
turns 360 degrees. Half a circle must therefore be 180, and half again
must be 90.
To draw a right arc you can use

TOARCR
REPEAT 18 [FD 5 RT 10]
END

and to draw a smaller left arc

TO ARCL
REPEA T 9 [FD 10 LT 10]
END

Using pi (17")
To vary the radius ofthe circle you need 17". The next procedure uses the
formula 217"/360 = 0.0174. The circumference of the circle is 360
degrees and therefore the radius (R) must be 360 divided by 217". To
draw a circle, the turtle must move forward by 217"R/360 for each step,
and turn by 1 degree.

TO CIRCLE5 :RADIUS
REPEAT 360 [FD :RADIUS * 0.0174 RT 1]
END

Circular patterns

Here are some procedures for you to experiment with

TO KREIS :SIDE
REPEAT 10 [FD :SIDE RT 36]
END

TO KREISI :SIDE
FD :SIDE LT 72 FD :SIDE LT 72
KREIS :SIDEI2 RT 72
BK :SIDE RT 108
IF HEADING = 0 [ST0P]
KREISI :SIDE
END
50 Turtle Fun: LOGO for the Spectrum 48K

KREIS} uses KREIS as a subprocedure. Note also that :SIDE occurs


in KREIS and KREIS 1. Its value is transferred from KREIS} to
KREIS.

TO PEACOCK :SIDE
FO :SIDE LT 72 FD :SIDE
LT 72 KREIS :SIDE/2 KREIS :SIDE RT 72
BK :SIDE RT 108
IF HEADING = 0 [STOP]
PEACOCK :SIDE
END

TO RINGS :SIDE
CIRCLE4 :SIDE RT 36
IF HEADING = 0 [STOP]
RINGS :SIDE + :SIDE/4
END
Looking at circles 51

This procedure uses CIRCLE4 as a subprocedure.

A squashed circle

Can you draw this shape accurately with a pencil? You cannot use a
compass or a dustbin lid. Drawing a squashed circle or an ellipse, as it
is officially called, is easy with the turtle.

TO ELLIPSE
REPEA T 2 [REPEAT 45 [FD 1 RT 2] REPEAT 45 [FD
2 RT 2]]
END

You can create a whole series of ellipses by using SETSCRUNCH


(SETSCR). This command sets the proportions of any figure to any
size you wish.
52 Turtle Fun: LOGO for the Spectrum 48K

TO EGG
REPEAT 2 [REPEAT 45 [FD 0.5 RT 2] REPEAT 45
[FD 3 RT 2]]
END

Now type SETSeR 99 1


The next example uses SETSeR inside the procedure to produce a
series of eggs of diminishing sizes. It uses the procedure EGG to draw
the eggs.

TO ELLIPSEl
SETBR 0 SETBG 0 SETPe 1
SETSeR [100 100] EGG L T 45
SETseR [90 90] EGG L T 45
SETseR [80 80] EGG L T 45
SETSeR. ..
SETseR [30 30] EGG L T 45
END
Section 10

Pot-pourri

If you look up 'pot-pourri' in a dictionary you will find a definition


something like this - 'a mixture of dried petals and spices ... a
miscellaneous collection of writings and ideas ...'
In this section you will indeed find a pot-pourri. You will find a
pot-pourri of LOGO ideas and projects that use procedures covered in
this book. Dig around and pick out what you think might be useful for
your own projects. The procedures in this section are only ideas, they
are not complete in themselves.

Seascape and landscape

TO CALMSEA
PU SETPOS [-126 -30]
PD SETH 0 RT 90 SETPC 5
SETBG 1
WAVE 1
END

53
54 Turtle Fun: LOGO for the Spectrum 48K

This procedure draws a picture of the sea at the bottom half of the
screen [-126 -30] by calling the subprocedure WAVE.

TO WAVE :STRIPE
FD 200 RT 90
PU FD :STRIPE LT 90 PD
IF :STRIPE > 10 [STOP]
WAVE :STRIPE + 1
END

TO SUN-SET
PUHTHOMEPD
SETBG 1 SETPC 3
POLY 0.1200.014
PU HOME PD SETPC 2
POLY 0.1 20 0.1 10
END

This procedure uses a subprocedure called POLY.

TO POLY :SIZE :ANGLE :INCREMENT :LENGTH


FD :SIZE
RT:ANGLE
IF :SIZE > :LENGTH [STOP]
POLY :SIZE + :INCREMENT :ANGLE :INCREMENT
:LENGTH
END

TO MOUNTAINS
RT45
FD 5 + RANDOM 10
IF OR YCOR > 50 YCOR < 0 [SETH 20 +
RANDOM 170- HEADING]
MOUNTAINS
END

TO TREE :SIZE
IF :SIZE <2 [STOP]
FD :SIZE
RT 15
TREE (3 * :SIZE/4)
Pot-pourri 55

LT 30
TREE (3 * :SIZE/4)
RT 15
BK :SIZE
END

Producing a regular pattern

TO TILE :SIDE
REPEAT 4 [FD :SIDE LT 45 FD :SIDE BK :SIDE
RT 135]
END
56 Turtle Fun: LOGO for the Spectrum 48K

TO TILEI :SIDE
REPEAT 4 [FD :SIDE LT 45 FD :SIDE LT 45 TILE
:SIDE RT 45 BK :SIDE RT 135]
END

TO TILE2 :SIDE
REPEAT 4 [FD :W LT 45 FD :SIDE LT 45 TILE!
:SIDE RT 45 BK :SIDE RT 135]
END

Artificial Intelligence

For a number of years some computer scientists have been building


computers that can learn to recognise shapes, colours and in some
instances carryon a human conversation. The building of such
'intelligent' machines belongs to the science of Artificial Intelligence.
You too can write procedures that change your own screen turtle
into an 'intelligent' bug! By using coordinates, it is very easy to produce
a program in which the turtle behaves like a simple organism such as a
flatworm or a flea. Simple animals like the flatworm, for example, do
not have a sense of smell but will avoid bright light or unpleasant
substances in the surrounding water. Their reactions are extremely
basic.
You can imitate or simulate this reaction to light by setting
coordinates for a particular area of the screen which tell the turtle to
avoid that area.
Ideally you should find some real 'beasties' and observe them before
you start writing a simulation. But here's something to get you started.
Pot-pourri 57

The intelligent bug

We begin by dividing the screen into two halves. The top half is the
LAND and the bottom half is WATER. The plan is simple. If the turtle
is at the top half of the screen then do such and such. If the turtle is at
the bottom half of the screen do something else. In the meantime, move
about the screen in a random fashion. In this program our beasty runs
on the land, leaving a random trail all over the top half of the screen
and whenever it moves into the area called WATER it begins to 'swim'
with its pen up at the bottom half of the screen.
To write this program we need three procedures, WATER, LAND
and BEASTY.

TO WATER
FD 25 RT 90 - RANDOM 180
END

TO LAND
PD FD 15 WAIT 50 RT 45 - RANDOM 90 PU
END

TO BEASTY
IF YCOR > 0 [LAND] [WATER]
BEASTY
END

The 'intelligent' conditions (Y coordinates) are set in the procedure


BEASTY. The turtle's movement is defined in WATER and LAND.
This program is very basic. Can you improve on it?
58 Turtle Fun: LOGO for the Spectrum 48K

Treacle-pops

Our beasty this time is more sophisticated. It possesses a sense of smell.


But its eyesight is atrocious!

TO TREACLE
FD 5 LT RANDOM 360
IF (AND XCOR > 10 XCOR < 20 YCOR > 10 YCOR
< 20) [SETCUR [16 10] FLASH PR
[TREACLE-POPS] STOP]
TREACLE
END

TO JAR
PU SETPOS [10 10] PD
SETPOS [20 10] SETPOS [20 20]
SETPOS [20 10] SETPOS [10 10]
PU FD 20 + RANDOM 80
TREACLE
END

To start this program you type JAR. The beasty flies about the screen
until it lands in the jar of treacle.
Pot-pourri 59

Sandhopper's picnic

TO SANDHOPPER
SETBG 6 SETPC 0
IF (AND YCOR > -20 YCOR < 20 XCOR > -20
XCOR < 20) [PD SOUND [0.05 -22] FD 5
RT RANDOM 360] [PU FD 50
RT 90 - RANDOM 180]
SANDHOPPER
END

In this procedure the turtle is a sandhopper. It hops about on the sand


(SETBG 6) searching for tasty morsels. The area of sand is divided into
cross-shapes plotted by YCOR and XCOR. Whenever the sandhopper
lands in one of these areas, it says "yum yum" (SOUND [0.05 -22])
and begins to walk over the food, leaving its tracks in the sand.
Notice that the logical operator AND is used immediately after IF,
followed by the inputs for YCOR and XCOR. If you wish to use AND
with more than two inputs, you have to place AND inside parentheses.

(AND YCOR > -40 ... )

If the sand hopper lands in the plotted area then it is

[PD FD 5 RT RANDOM 360]

otherwise
[PU FD 50 RT 90 - RANDOM 180]

which sends the sandhopper hopping around the screen.


Section 11

The LOGO mouse

A novel and exciting way to display data on your screen is to use a


window-system.
The screen is divided into a number of windows (usually four), which
when touched by the turtle call a specific procedure.
In the world of big business, the turtle or cursor is controlled by a
'mouse'. This is an electronic device consisting of a box with one or two
buttons. The mouse is held in the hand like a remote control device. By
pressing one of the buttons, the mouse controls the screen cursor which
in turn can be moved directly to any window displayed on the screen.
Pressing the second button calls data for a specific window shown on
the screen.
60
The LOGO mouse 61

These windows can also be depicted as graphic symbols. Sometimes


you will see a symbol of a typewriter (word processor) or a calculator
(for business calculations) or even a pair of scissors (for editing files
etc.). The busy executive can sit back in his leather swivel chair and call
all sorts of information on to the screen simply by moving and
squeezing the mouse!
Before you think of abandoning your keyboard, the LOGO mouse is
purely fictional. It is not yet an extra piece of hardware, a peripheral
that you can plug into your Spectrum. It is just my name for the turtle
when it is used to display data using windows.
With the LOGO window-system, you can switch between the
windows by moving the turtle-mouse. In the following program you
can switch between household bills, addresses, recipes and leisure
windows. Is the window-system easier to use than a one-thing-at-a-
time approach?
Try this program and decide for yourself. The main procedure is

TO MOUSE
SETBG 0 SETPC 7
FRAMES
MOVE
IF (AND XCOR < -10 XCOR> -127
YCOR < 87 YCOR > 10) [CS RECIPES]
IF (AND XCOR < -10 XCOR > -127
YCOR < -10 YCOR > -88) [CS ADDRESSES]
IF (AND XCOR < 127 XCOR > 10 YCOR < 87
YCOR < 10) [CS BILLS]
IF (AND XCOR < 127 XCOR > 10 YCOR <-10
YCOR> -88) [CS LEISURE]
MOUSE
END

TO FRAMES
SETCUR [3 5] FLASH PR [RECIPES]
SETCUR [22 5] FLASH PR [BILLS
SETCUR [3 15] FLASH PR [ADDRESSES]
SETCUR [22 15] FLASH PR [LEISURE]
END
62 Turtle Fun: LOGO for the Spectrum 48K

Ireelpes I

This subprocedure displays the windows on your screen.

TO MOVE
PU MAKE" ANS RC
IF :ANS = "F [FD 30]
IF :ANS = "R [RT 45]
IF :ANS = "L [L T 45]
PD
END

This enables you to move the turtle to select a window.


Touching RECIPES for example with the turtle-mouse calls the
procedure RECIPES which is defined as follows.

TO RECIPES
SETBG 2
FRAMESI
IF (AND XCOR < -10 XCOR > -127
YCOR < 87... [CS CHINESE]
IF (AND XCOR < -10 XCOR > -127
YCOR < -IO... [CS CAKES]
IF (AND XCOR < 127 XCOR > 10
YCOR < 87 ... [CS FISH]
IF (AND XCOR < 127 XCOR > 10
The LOGO mouse 63

YCOR < -l0 ... [CS VEGETARIAN]


RECIPES
END

This in turn displays four windows labelled CHINESE, FISH,


CAKES, and VEGETARIAN.
The subprocedure FRAMES I is really a repeat of FRAMES. Only
the print statements have changed!

TO FRAMESI
SETCUR [35] PR [CHINESE]
SETCUR [22 5] PR [FISH]
SETCUR [3 15] PR [CAKES]
SETCUR [22 15] PR [VEGETARIAN]
END

Touching the window CHINESE will call the procedure CHINESE


which plays an oriental tune and displays three Chinese dishes.

TO CHINESE
SOUND [1 11] SOUND [1 13] SOUND [1 15]
SOUND [1 18] SOUND [0.5 20] SOUND [0.5 23]
SOUND [0.5 20] SOUND [0.5 18] SOUND [1 15]
SOUND [1 13]
TS PR [EGG-FLOWERSOUP PAO-TZU
SNOW-MOUNTAIN]
CHINESE
END

Again the Chinese recipes are subdivided into individual dishes. Can
you write a procedure that will allow you select one dish at a time?

TO EGG-FLOWER-SOUP
PR [Egg Flower Soup]
PR [1 egg]
PR [1 - 2 pints high broth]
PR [1 tablespoon chopped chives]
PR [ teaspoon sesame oil]
END
64 Turtle Fun: LOGO for the Spectrum 48K

TO PAO-TZU
PR [Pao-Tzu]
PR [lIb flour]
PR [I teaspoon dried yeast]
PR [ pint water]
PR [I tablespoon sugar]
END

TOSNOW.MTN
PR [Prawns on the snow mountain]
PR [6 oz fresh peeled prawns]
PR [10 egg whites]
PR [2 teaspoons cornflour]
PR [ teaspoon salt]
PR [I oz minced smoked ham]
PR [2 tablespoons chopped coriander leaves]
PR [oil for deep frying]
END
PART 2 WORD FUN

65
Section 12

Looking at lists

LOGO not only offers you turtle graphics; it can also handle words.
This ability to handle words is called list processing.

Everyday lists

Lists are an everyday feature of our lives. We have shopping lists, club
membership lists, lists of things to do, lists of information such as
birthdays and other important dates, lists of addresses and telephone
numbers and, if you are a very busy person, lists of lists! The list is
endless. Information of all sorts can be written down as a list. The same
applies to LOGO. You can store information or data in the form of
lists, which in turn can be manipulated (processed) by the computer.

LOGO lists

In LOGO lists can be made up from words or numbers, or a mixture of


both. A shopping list, for example, might contain the following items-
milk, eggs, butter. To write this same list in LOGO, all you have to do is
place the items inside brackets

[milk eggs butter]

In this instance, the brackets are equivalent to the piece of paper on


which the shopping list is written. You can, if necessary add to the list,
say for example - Soy sauce - or you can cross off an item or items. To
66
Looking at lists 67

go a stage further, you can have a list (or lists) within the main list.
In everyday terms this could be in the form of

milk eggs butter (from Superstores)


fruit veg fish (from North End Market)

Milk, egg and butter now belong to the list of items that are to be
purchased from Superstores, while fruit, veg and fish are to be
purchased from the Market.
In LOGO you can write this as

[[milk eggs butter from Superstores] [fruit


veg fish from North End Market]]

The outer brackets represent the shopping list, while the purchases
from the different shop/market are written as separate lists.

Note for the milkman


6 pints
2 doz eggs

Things to do
Letter to Aunt Mabel
Collect shoes
Return library book

In LOGO you can write these lists as follows

[[6 pints] [2 doz eggs]]

The outer brackets represent the note for the milkman, while each
separate item is written as an individual list

[6 pints] [2 doz eggs]


[[Letter to Aunt Mabel][Collect shoes][Return
library book]]

Again the outer brackets represent the list 'Things to do', while each
thing to be done is written as an individual list.
By the way, how many items are there in this list? The answer is 3.
68 Turtle Fun : LOGO for the Spectrum 48K

Now have a look at this one

PRINT [Please leave five pints today]

How many items in this list? The answer this time is 5! There are no
individual lists inside the main list, but only items, that is five words.
Try some more!

PRINT [apple plum apricot pear]

This is a list of fruit containing four items.

PRINT [[Captain Tee] Selina Doc]

This is a list of names which contains three items. It is made of one list
[Captain Tee] and two words - Selina and Doc.

How many items in these lists?

1. [A BCD I 2 3]
2. [[A B] C D [1 23]]
3. [Ash Beech Fir Lilac]
4. [Clive [Jill Ball] David]
5. [Manchester [York] Cambridge [Camberley]]
6. [ ]

There are no prizes for correct answers, but hopefully your answers
should be

1. 7
2. 4
3. 4
4. 3
5. 4
6. 0

In list number 5, I have written York and Camberley as lists, which


although it does not seem to make sense, can be done all the same.
List number 6 is what is called an empty list. It is a bit like having a
blank piece of paper ready for you to write down your items . You could
call it a blank list if you like.
Looking at lists 69

By now you may have realised that anything placed inside brackets is
in LOGO terms - a list. And what is more you can use as many lists as
you want. You can have lists inside lists inside lists inside lists ... If you
like playing around with brackets (that is, if you are a parenthetico-
phile) you can have a whale of a time thinking up all sorts of
combinations and variations. This one I call 'maximum security'

[[[[[[[[0]]]]]]]]

and this one I call Russian dolls

[Galya [Luba [Xenia [Anna [Masha]]]]]

fA
~
Is

REPEA T 4 [FD 20 RT 90]

a list? Yes, [FD 20 RT 90] is a list of commands. It contains instructions


and therefore we can call it a list of instructions.

Remember! A list is made from individual items which can themselves


be lists
70 Turtle Fun: LOGO for the Spectrum 48K

[[Pink Panther][Bugs Bunny][Micky & Donald]]

or it can be made from individual words

[Tom Jerry Pluto Goofy]

Using lists in procedures

You have already used lists with Turtle graphics, for example

IF :SIZE > 100 [STOP]

where [STOP] is a list that contains one item, the command word
STOP.
In the procedure PLAY, the line

IF :REPL Y = "0 [FD 10]

contains the list [FD 10].


Section 13

The Postcard Machine

The following procedure called POSTCARD demonstrates how lists


are used with words. This procedure automatically writes postcards for
you, using a random selection of phrases. For demonstration purposes
I have only used a random of 3. You can in practice have as many
random phrases, names, and endings as you wish.
The Postcard Machine is a very useful item to have on holiday with
you. (You can easily pack your Spectrum into a suitcase and carry your
cassette player with your bucket and spade. As for a TV - well most
hotels have one.)
Let's have a look at the procedure called POSTCARD.
7J
72 Turtle Fun: LOGO for the Spectrum 48K

TO POSTCARD
PR SE [DEAR] :TITLES o
PR :MESSAGE
PR :ENDINGS
PR [JO]
POSTCARD
END

As mentioned before, use a top-down approach. Write out the main


procedure and then define any subprocedures or MAKE statements
later. Write, in other words, what you want to achieve. Work out the
details later. If you apply this top-down technique to any kind of
problem, from planning a holiday to playing a good game of chess, you
will be surprised how a little overall planning can help you achieve
successful results.
The originator of LOGO, Seymour Papert, demonstrates in his
book 'Mindstorms' how you can use procedures to learn juggling. It is
said that young programmers learning LOGO with Professor Papert
not only learn how to juggle at the same time as programming the
turtle, but they also learn how to walk on stilts!
Anyway before you start balancing your Spectrum on the end of
your nose, let's get back to our procedure POSTCARD. Having
written the procedure POSTCARD, you are now ready to define

:TITLES :MESSAGE :ENDINGS

For this you can use MAKE statements. Could you use subprocedures?
In theory yes, but unfortunately the Sinclair version of LOGO, like
some other LOGOs, does not allow you to do this. You have to write
the MAKE statements outside of the procedure POSTCARD. Having
written your random phrases using MAKE statements, there is
therefore no point in putting them inside procedures.

MAKE "TITLES RANDOM 3


IF :TITLES = 0 [PR[DEAR WEMBLEY]]
IF :TITLES = 1 [PR[DEAR KOLKA]]
IF :TITLES = 2 [PR[DEAR ZIGGY]]
The Postcard Machine 73

MAKE "MESSAGE RANDOM 3


IF :MESSAGE = 0 [PR[WISH YOU WERE HERE]]
IF :MESSAGE = 1 [PR[WEA THER'S JUST FINE!]]
IF :MESSAGE = 2 [PR[HA VING GREAT FUN]]

MAKE "ENDINGS RANDOM 3


IF :ENDINGS = 0 [PR[BEST WISHES]]
IF :ENDINGS = 1 [PR[YOURS TRULY]]
IF :ENDINGS = 2 [PR[MUCH LOVE]]

Note the use of recursion in POSTCARD. If you forget to use


recursion, you will only be able to write one postcard at a time.
Section 14

Autopoet

This program goes a stage further and expands the use of random
phrases by teaching your computer to write poetry! The lines of poetry
(borrowed from Shakespeare) are included in three separate MAKE
statements.

MAKE "A [[phrase 1] [phrase 2] [phrase


3] [phrase 4]]
MAKE "B [[phrase 1] [phrase 2] [phrase
3] [phrase 4]]
MAKE "e [[phrase 1] [phrase 2] [phrase
3] [phrase 4]]
74
Autopoet 75

These MAKE statements are then used as inputs to the procedure


called PICK. The PICK procedure picks out random phrases and
prints them on the screen.

TO PICK :PHRASE
PR ITEM (1 + RANDOM COUNT :PHRASE) :PHRASE
END

ITEM and COUNT are both primitives, which you will find explained
in the User Manual. Briefly, ITEM outputs an item from a list, while
COUNT tells you how many items there are in a list. So in PICK we ask
the computer to make a random COUNT and pick out one of the
phrases in the MAKE statement and print it.
The variable :PHRASE is used to put the lines of poetry into the
procedure PICK. You could call this variable any name you like.
The final program is called AUTO. POET and is as follows

TO AUTO. POET
PICK :A
PICK :B
PICK :C
END

Let's now put some real phrases from Shakespeare's sonnets into the
MAKE statements A, B, and C.

MAKE "A [[When I do count the clock that tells the time]
[And see the brave day sunk in hideous night] [Not from the
stars do I my judgement pluck][When I consider every thing
that grows]]
MAKE "B [[Then of thy beauty do I question make] [Since
sweets and beauties do themselves forsake] [Or say with
princes if it shall go well] [Thy end is truth's and beauty's
doom and date]]
MAKE "c [[Much like than your painted counterfeit]
[Neither in inward worth, nor outward fair] [Can make you
live your self in eyes of men] [And you must live, drawn by
your own sweet skill]]

If Shakespeare is not quite your cup of tea, or should I say tankard of


ale, then try some traditional verse, or better still make up your own.
Section 15

Master Mind

A popular activity with many LOGO programmers is writing quiz


games. By making use of the operators READ LIST (RL) together with
IF, you can create an interactive program that you can tryout on your
friends.
If you remember, RL waits for you to type something at the
keyboard, while IF allows you to set conditions to the answers to your
questions.
Here is a quiz game that can ask you questions about any subject in
the world!

TO MASTER.MIND
TUNE
FLASH PR [What is your subject?]
MAKE HANS RL
76
Master Mind 77

PR SE [So your subject is] :ANS


SETTC [7 3]
WAIT 120 CT
NORMAL PR [Who was the first person to study
this subject?]
MAKE "ANSI RL
PR (SE [Well done!] :ANSI [ was the first
person to study] :ANS)
PR [ ]
PR [I'm sorry what was your subject?]
MAKE" ANS2 RL
IF :ANS2 = :ANS [PR[You have a very good
memory.]] [PR[That is not what you said!]]
WAIT 20CT
PR [Now for a general knowledge question]
WAIT 130 SETTC [7 1] CT
PR [Who was the first man in Scotland?]
MAKE" ANS3 RL
IF :ANS3 = [MACADAM] [PR[YES you are
correct!]] [PR[No I'm sorry the correct
answer is MACADAM]
WAIT 130 CT
MASTER.MIND
END

The quiz begins with a jingle called TUNE that you can write yourself.
The uses of FLASH , WAIT, CT, SETTe, NORMAL, etc. are purely
cosmetic. They can be used how you like to present the text on the
screen.
RL or READ LIST waits for the player to type in an answer at the
keyboard . The MAKE statement with HANS enables you to use the
replies as part of the computer's own sentences as in

PR SE[So your subject is] :ANS

The computer next uses the player's reply :ANS 1 and :ANS in its next
sentence on the screen.

PR (SE[Well done!] :ANSI [was the first


person to study] :ANS)
78 Turtle Fun : LOGO for the Spectrum 48K

In this line of the procedure parentheses have been used as well as


square brackets. This is because LOGO states that SE or SENTENCE
must be placed inside parentheses if there are more than two inputs .
Recursion has been used in the last line in order to rerun the program.
Section 16

Adventure games

Since LOGO can handle words, you can use LOGO to write your own
adventure games. For those of you who are not familiar with this type
of game, you, the player, assume the role of the hero or heroine.
Depending on the game, you can be a swash-buckling knight or Super
Girl. You can be an animal or an explorer. The games take place in a
fantasy world in which you have to overcome obstacles and reach a
final goal. On the way you can meet monsters, find treasure and
generally use your wits to solve problems and defeat your opponents.
To begin, here is a simple adventure game in which you have to find the
Pink Punk. He is hiding somewhere in the house. You have to search
for him. The figure opposite shows you a plan of some of the rooms
used in the game. A room in an adventure is simply a location and
could be a wood or a cave, and not just a room of a house.
It is a good idea to draw a plan of the rooms that you wish to use
before you start programming. I have used a separate procedure for
each room (location). By typing the name of a procedure, you are
transported at once to that location. I have also used RANDOM to
make the game a little more interesting. The whole game is only an
outline for an adventure. It is only meant to provide you with some
ideas to use in your own adventure games.
79
80 Turtle Fun: LOGO for the Spectrum 48K

Downstairs easement

yellow
+une. etc...

Contents
choice,

Cupboard

Silverdoor

Find the Pink Punk!

TO START
CS SETBG 3 SETPC 7
SETCUR [3 10]
BRIGHT 1
FLASH PR [FIND THE PINK PUNK!]
TUNE
SETCUR [3 12]
Adventure games 81

PR [Alas the main door in the Great Hall is locked. To


escape you must find the Pink Punk who has the key. But
where to look for him? DOWNSTAIRS
or UPSTAIRS????]
END
TO UPSTAIRS
TS SETTC [7 I] TUNE
MAKE "ANSI RANDOM 2
IF :ANS I = 0 [PR[1t is too dark for you to see. Go back to
the Great Hall and pick up a candle. Try UPSTAIRS
again.]]
IF :ANS I = I [PR[Y ou continue along a dark narrow
passage until you come to a central corridor where you
see four doors. BLUE, GREEN, YELLOW and PINK.]]
END

TO YELLOW
TUNE TS SETTC [7 3]
PR [ In the Yellow bedroom you find some objects. Is the
Pink Punk hiding in one of them? Type CONTENTS to
find out what the objects are]
END

TO CONTENTS
TSSETTC[75] 7
FLASH PR [WARDROBE BED CUPBOARD] •
END
82 Turtle Fun: LOGO for the Spectrum 48K

TO WARDROBE
TUNE TS SETTC [7 1]
PR [The Wardrobe is full of ancient dressing-gowns. But at
the back there are two secret doors. One is SILVER, the
other is BRONZE.]
END

TO BRONZE
TUNE TS SETTC [7 3]
PR [You go through the Bronze door and find two passages.
One is a NARROW passage while the other is a BROAD
cheerfully-lit passage.]
END

TO BROAD
TUNE PP SETCUR [3 10] BRIGHT I
PR [Here's your key Sir!]
END

TO TUNE
SOUND [120] SOUND [0.222]
SOUND [I 23] SOUND [0.2 19]
SOUND [0.5 20] SOUND [0.15 22]
SOUND [0.5 23] SOUND [0.1 26]
SOUND [1.525]
END

TO DOWNSTAIRS
TS SETTC [7 4]
SOU ND [I -18] SOUND [1 -19]
SOUND [0.6 -20]
PR [You see before you a winding staircase leading down to
the kitchen. At the bottom of the stairs there is a huge
hairy hound asleep. You could if you are very careful
tiptoe past it. Will you dare, YEA or NAY?]
END

TOPP
END
Adventure games 83

This last procedure draws the head of the Pink Punk on the screen. You
can fill in the details!
How you display the text is purely a matter of choice. I have used
SETCUR to set the cursor roughly in the middle of the screen, and I
have used BRIGHT 1 to display the text "Find the Pink Punk". I have
also included TUNE, which appears every time you get closer to
finding that elusive cat. Background colour and text can be set using
either the graphics mode SETBG and SETPC or by using the text mode
SETTC followed by the background colour and the text colour. Again
this is a matter of choice. I find that TS (TEXTSCREEN) is necessary if
you do not want all the previous text appearing at the same time as the
new text on the screen. You can of course omit TS if you wish.
You may wish to develop this program and for this purpose I have
left some of the rooms undefined. If you are not interested in the Pink
Punk, you can still use this program as a model for your own ideas.

The Purple Planet

Useful LOGO primitives

I FLASH NORMAL LPUT MEMBERP RL I


FLASH produces flashing text on the screen. Too much of it though
can give you square eyes!
84 Turtle Fun: LOGO for the Spectrum 48K

NORMAL returns to normal text after the FLASH command.


Phew! thank goodness for that!
LPUT places an object, that is a LOGO word, at the end of a list. In
this game it means place an object in the last position in the inventory.
MEMBERP looks to see if the object that you have chosen belongs
to the list of objects in the procedure. If it does, then take a particular
action. In this program it allows you to enter certain rooms, provided
that you have the correct object.
In this next adventure we go a stage further by including an
inventory of things that you can collect or discard on your journey.
There is also a menu which provides the player with information about
the game. The adventure takes place on the Purple Planet, a fantasy
world in which you have to find food, water and a special ore to refuel
the engines of your spaceship. To find out more, let's write the
procedure called MENU.
TO MENU
SOUND [] SOUND [] etc.
LANDSCAPE
WAIT 200
SETCUR [3 10]
TS FLASH PR [Welcome to the PURPLE PLANET]
NORMAL PR [You have just landed. You must find water
and a special ore to refuel your spaceship's engines.
During this game you may collect objects that you find
on the way. You will also need to remember these
command words]
PR [OPEN HIT CLOSE SHOOT ENTER CHECK]
PR [You can also use THROW to discard objects; however,
this command must be followed by ", for example
THROW "HAMMER or THROW "SWORD. There is
one snag; whenever you throw an object you lose
everything else in the inventory. You will have to think
up a procedure for yourself, if you wish to discard and
retain objects that you have collected.]
TAKE
BEGIN
END
I have left out the inputs for SOUND. You may put your own in. I like
to begin with a short jingle, followed by a picture of the purple
landscape.
Adventure games 85

TO LANDSCAPE
LT 90 FD 200 BK 600 RT 45
FD RANDOM 100 LT RANDOM 100 HOME
L T 20 FD RANDOM 50 LT RANDOM 90 FD RANDOM
100 SETH 0
END

There is plenty of scope here for improvement, as you will see when you
run LANDSCAPE!
After the text, MENU calls the subprocedure TAKE. This allows
you to take one useful object with you. The second subprocedure
BEGIN starts your journey on the planet.

TO TAKE
PR [Before you set off to explore the planet, you may take
one of the following objects]
FLASH PR [SWORD HAMMER BOTTLE]
PR []
NORMAL PR [Remember you can only choose one object.
Which one will you take with you?]
MAKE "INV LPUT RL :INV
END

A feature of Sinclair LOGO, like many other versions of LOGO, is that


you have to write

MAKE "INV [ ]

outside of the procedure TAKE in order to create a storage procedure


for the objects that you collect on your journey. INV used here is short
for INVENTORY, which means a collection of things.
The MAKE statement

MAKE "INV [ ]

creates an inventory for objects collected on route. The empty list [ ]


sets up a blank inventory for you to fill. Remember to leave a space
between the two brackets; if you forget , the MAKE statement will not
work. Whenever you wish to check what you have collected, you type
CHECK, which we will define as follows
86 Turtle Fun: LOGO for the Spectrum 48K

TO CHECK
SETTC [3 7]
SOUND [ ]
FLASH PR :INV
SETTC [7 1]
END

If you have, for example, picked up HAMMER in the procedure


TAKE, you can now type CHECK to see if you have really got it!
An alternative to the TAKE procedure could be

TO GET :OBJECT
MAKE "INV LPUT :OBJECT :INV
PR SE[You have picked up the] :OBJECT
END

This enables you to pick up specific objects by naming them. The


MAKE statement places the object in the inventory.

GET "BOTTLE

Writing GET as a procedure does tend to limit its use, since once you
have used GET you find yourself outside the current room. Could you
use GET some other way to pick up objects and keep the game moving?

TO BEGIN
WAIT 50
SETTC [7 2]
CT
PR [Now you are ready to set off. You consult your
compass. But which way?]
END

You are left to decide for yourself. You must find the appropriate
word! Seasoned players of adventure games will be familiar with this
type of decision. They usually have a vast dictionary of useful words
which enable them to play adventures. But for those of you who are
new to the adventure game, the clue is 'compass'.
Adventure games 87

TO EAST
SETTC [1 7]
PR [You see a dark cave in front of you.]
IF RL = [ENTER] [PR [Inside the entrance you find an old
lantern and a stick on the ground.]] [PR [You can't use
that word! Try EAST again.]]
IF RL = [LANTERN] [CAVE1] [HOLE]
END

If you pick up the lantern you are immediately transported to CAVE 1,


which is defined as follows

TO CAVEI
PR [Off you go]
MAKE "INV LPUT "LANTERN :INV
CAVE2
END

If on the other hand you are unfortunate to choose the stick (or use
another word) you are plunged into the procedure HOLE!

TO HOLE
PR [It is so dark that you fall down a deep hole and that's the
end of you!]
END

TOCAVE2
PR [You see an upper and a lower passage. Which one will
you choose?]
END
88 Turtle Fun: LOGO for the Spectrum 48K

TO LOWER
PR [You find a door covered with brass buttons]
IF RL = [PUSH] [CA VE3] [CA VE2]
END

TO CAVE3
PR [The door swings back to let you through]
WAIT 200
PR [At the end of this passage there is a light. You hear a
strange noise]
WAIT 100
SOUND [0.5 -14] SOUND [0.5 -15] SOUND [1 -16]
SOUND [2 -2]
WAIT 200
PR [You discover an underground city]
WAIT 100
CITY
END

TO UPPER
PR [You see a red door]
WAIT 50
IF MEMBERP [HAMMER] :INV [PR [You strike the
door with your hammer and the door opens]] [(ANS)
STOP]
CAVE4
END

TOANS
PR [You can't enter because you did not pick up the
hammer!]
CAVE2
END

TOCAVE4
PR [You arrive back at the surface of the planet]
END

TO CITY
WAIT 100
PR [You have struck lucky! There is more than enough
Adventure games 89
special ore here to refuel your engines. The city is also
inhabited by friendly robots who will help you to take
the ore to your spaceship]
WAIT 50
PR [Your next task is to find water and food for yourself and
your crew]
WAIT 200
BEGIN
END

TO AIRLOCK
SETTC [02]
PR [You enter an airlock. The door closes behind you and
you suddenly notice that the oxygen is running out. Be
quick and find a way out!]
WAIT 200
IF RL = [SHOOT] [PR [You melt down a concealed door
and enter an underground city] CITY STOP] [PR
[Hurry up you only have 50% oxygen left]]
WAIT 150
PR [Your oxygen supply is nearly up!..]
IF RL = [SHOOT] [PR [You melt down a concealed door]
CITY STOP] [PR [Too late you have snuffed it!]]
END

TO WEST
PR [You find yourself in a vast arid desert. But after a few
hours of wandering you find a waterhole]
IF MEMBERP [BOTTLE] [PR [You fill your bottle]
[(ANS2)]
DESERT
END

TO ANS2
PR [You can't go on without a bottle!]
MENU
END

TO DESERT
PR [After walking for another hour you come to a steep
mountain range. At the foot of the mountains there are a
90 Turtle Fun: LOGO for the Spectrum 48K

number of deep craters. Two of them have ladders


leading down into the darkness below. One oi them has a
green ladder, while the other has a brown ladder.]
END

TO BROWN
PR [The ladder takes you down on to a sandy floor. There is
a damp smell. To your left you see a sword and an old
rope lying on the sand]
IF RL = [SWORD] [PUT] [ROPE]
WAIT 100
PR [You continue along a low tunnel until you reach a
chamber with metal walls. There is a door and it is
partially open.]
IF RL = [ENTER] [PR [You have entered an airlock. The
door suddenly closes behind you.] AIRLOCK STOP]
[PR [That is not the correct command. Try BROWN
again!]]
END

TO GREEN
PR [The ladder descends into a deep well. If you like
swimming, you might explore further!]
END

TO ROPE
MAKE " INV LPUT "ROPE :INV
END

TO PUT
MAKE "INV LPUT " SWORD :INV
END

TO SOUTH
PR [The terrain is very rocky and uneven . There are huge
sand dunes and wide gaping craters. The whole area is
very gloomy and creepy]
SOUND [1-10] SOUND [0.5 -11] SOUND [1-20] SOUND
[1 -2I[ SOUND [1 -22]
SETTC [0 3]
Adventure games 91

PR [Just over the next rise you suddenly see a huge hairy
Nurk. It attacks you]
WAIT 100
PR [You can kill it if you use the correct weapon]
IF RL = [SHOOT] [PR [The Nurk runs away in pain. You
are safe for the moment. Better choose another direction
before it is too late!]] [PR [The Nurk gets you.] MENU]
END
Any mistakes or blunders in your attempts to explore the Planet either
return you back to MENU or finish you off!

Writing your own games

Not all of the rooms are complete. You are free to write your own
procedures for NORTH and its subsequent rooms. I find it a good idea
to link all the rooms in the program by the use of random commands.
This use of random makes the game slightly different each time and
allows players to explore most of the rooms in one session.
Since you have the plan of the rooms you can of course modify the
program for your own games. Feel free to use the structure of the
Purple Planet, ifnot the story. Remember, how you write adventures is
up to you. Don't be influenced too much by commercial games. There
are no hard and fast rules on how adventures should be written.
Index

AND 59,61 Objects 16


arc 49 OUTPUT 16, 24
Artificial Intelligence 56
Papert, Seymour 72
BACK (BK) 6 Parentheses 16
Brackets 16, 66 PENDOWN (PD) 8
BRIGHT 80 PENUP(PU) 8
pi 49
calculator 3 POLY 34
circle 47 polyspirals 36
colon (:) 19 POSITION (POS) 28
conditional statement 29 Primitives 16, 18
COUNT 75 PRINT (PR) 16
procedure(s) 3, 11
database 32
RANDOM 9, 23, 24, 39
ellipse 51 READCHAR 25
READ LIST (RL) 76, 83
Find the Pink Punk! 80 recursion 13, 14, 15,47
FLASH 61,83 REPEAT 9
FORWARD (FD) 6 RIGHT (RT) 6

HEADING 48 Sandhopper's picnic 59


HIDETURTLE (HT) 8 Seascape 53
HOME 28 SENTENCE (SE) 18
SETBG 9
IF 25 SETCURSOR (SETCUR) 61
inspiral 39 SETHEADING (SETH) 28
ITEM 75 SETPC 9
SETPOS 58
LEFT (LT) 6 SETSCRUNCH (SETSCR) 51
List processing 66 SETTC 77
lists 16, 17,66 SHOWTURTLE (ST) 8
LPUT 83 SOUND 31
spirals 40
MAKE 19-21 spirolaterals 42
MEMBERP 31 , 83 STOP 39
subprocedures 13, 14
NORMAL 83

92
Index 93
The intelligent bug 57 WAIT 9,10
The Purple Planet 83 WINDOW 28
Total Turtle Trip (TTT) 48 window-system 60
TOWARDS 28
Treacle-pops 58 XeOR 58.61
variable(s) 16,18-24 yeOR 57,58,61
94

You might also like