Logo User Guide 151
Logo User Guide 151
User Guide
Version 1.5
Contents
Getting Started 5
ACSLogo Requirements 5
Downloading the Program 5
Tutorials 6
First Steps 7
Starting the Program 7
The Main Window 7
The Graphics Window 7
Commands 8
Help for Commands 10
Other Commands 10
Command Output 11
Arithmetic Expressions 11
Minus Signs 11
The Turtle 13
The Canvas 13
The Turtleʼs Position 14
The Turtleʼs Heading 15
Commands affecting Heading 16
Visibility 16
The Pen 17
Up or Down? 17
Pen Colour 17
Pen Width 17
Datatypes and Variables 19
Numbers 19
Operations on Numbers 19
Relational operators 20
Mathematical Functions 20
Words 22
Operations on Words 22
Lists 25
Operations on Lists 25
Variables 27
Flow Control 29
Repeating Commands 29
Run 31
Making Decisions 31
Thatʼs It? 31
Some More Examples 31
2
Procedures 33
The Procedures Window 33
Parameters 35
Comments 36
Local Variables 36
Outputting Results 36
Recursion 36
While and For 37
Thing 38
Importing Procedures 39
Graphics 40
Colours 40
Transparency and Opacity 41
Drawing Arcs 42
Text 43
Filling Shapes 43
Shadows 45
Images 46
Paths 47
FillCurrentPath 47
StrokeCurrentPath 48
Saving Paths 48
Text 48
Holes 50
Vector Graphics 55
Exporting Vector Graphics 55
Clipping Paths 57
Files 59
File Management Commands 59
File Manipulation Commands 63
Movies 65
Animation in ACSLogo 65
An Example 65
Speech & Music 67
Speech 67
Music 67
Appendix A: Menus 69
The ACSLogo Menu 69
The File Menu 69
The Export Submenu 70
The Edit menu 71
The Special menu 71
The Window Menu 72
3
The Help Menu 73
Appendix B: Preferences 75
The Turtle Tab 75
The Editing Tab 78
The Localisation Tab 79
Appendix C: Roll Your Own Turtle 80
Appendix D: Localisation 84
Prerequisites 84
The Application Bundle 85
Localisation Tasks 86
GUI Localisation 86
The .nib File 86
Localizable.strings 89
Logo Command Localisation 89
Command Table 92
Help and Tutorial Localisation 96
Tutorials 96
Help 96
Appendix E: Applescript 98
Applescript in General 98
Applescript and ACSLogo 98
Running Scripts 99
Local Applescript 99
Terminal 99
Remote Applescript 100
4
Getting Started
ACSLogo Requirements
ACSLogo runs on Mac OSX. The current version (1.5) runs on Leopard (OSX 10.5) and above.
At the time of writing, ʻaboveʼ is Snow Leopard (OSX 10.6), but it should run OK on the next few
versions.
There are older versions of ACSLogo on the website which will work with earlier versions of
the Mac OS.
5
Double-click on the program to start it up. When the program starts, youʼll see two windows - a
main window called Untitled, and another window called Untitled - Graphics:
The main window is where youʼll type in logo commands. Any drawing done by the turtle
shows up in the Graphics window.
Youʼll probably want to expand the Graphics window to its full size by hitting the green button
on its title bar.
Tutorials
Click on the Help Menu, and at the bottom youʼll see a list of tutorials from the tutorials folder:
Each of these will open an interactive tutorial about a specific subject. We will cover the same
ground in this book, so choose which suits you best.
6
First Steps
Starting the Program
Start the program by double-clicking on ACSLogo.app (the .app suffix may not be displayed
depending on your system settings).
When the program opens, you will see two windows – a main window called ʻUntitledʼ, and a
graphics window called ʻUntitled - Graphicsʼ.
7
Commands
In the main window, type this in on a line on its own:
Forward 100
Then, with the cursor still on that line, choose Execute from the Special menu.
In the Main window, press the Return key to go onto the next line, then type this in:
Right 90
Weʼre going to execute this command, but rather than do it from the menu, hold down the
Command key (on the left of the space bar) and press return (you're going to have to execute a lot
of commands, and doing it from the keyboard is a lot quicker than going back to the menu each
time).
Now move up to the previous line (the one with Forward 100) and press Command-return
again.
8
The turtle moves forward 100
pixels again.
Itʼs obvious from this that when we say Forward, where the line is drawn is dependent both on
the position of the Turtle and the direction it is facing.
Try using Forward and Right with different amounts, then try Left (which does as you would
expect).
If you misspell a command, Logo will complain:
Froward 100
unknown function Froward
You can press Command-Z (Undo) to get rid of the error message, then go back to correct the
command and execute it again. The commands weʼve looked at so far all take one parameter,
which is the amount by which to move or turn. If you leave that out, Logo will complain:
Forward
wrong number of inputs for Forward
Different Logo commands take different number of parameters – one, two, three, or none.
One command that takes none is ClearScreen. Execute it now and you will see that it clears
the screen and sets the Turtle back to the middle of the canvas, pointing straight up.
Commands are case-insensitive — you can type ClearScreen, clearscreen, or
clearSCREEN, and they will all do the same thing.
So far, youʼve typed in the commands individually on separate lines and then executed them
one at a time. You can highlight a sequence of commands and press Command-return to execute
them together. Type in these commands, highlight them, and execute them together:
Forward 100
Right 90
Forward 100
You can also type them all in on one line and execute everything on that line:
9
Forward 100 Right 90 Forward 100
Related commands.
You can see that Forward has an alternative, shortened, form – FD. The shortened forms of
commands can be handy when youʼre in a hurry.
The next line shows that Forward takes one parameter, distance.
Next is a description of what Forward does.
Finally, there are some links to other commands which are related in some way.
For many commands, youʼll also see some examples of their use.
This information can also be found in the ACSLogo Command Reference on the ACSLogo
website.
Other Commands
Weʼve only looked at Forward, Left and Right so far – these are the commands you will use
most of all, but there are many more commands — graphic commands like SetPenColour and
SetPenWidth to change the colour and width of the line drawn by the Turtle; commands which are
mathematical functions such as cos, sin, tan; control commands such as Repeat and If. Weʼll come
across these commands and many others in the following chapters.
10
Command Output
Many commands write information back to you:
Arithmetic Expressions
Anywhere you can write a number, you can write an arithmetic expression:
Forward 100 - 10
SetPenColour 2 * 3
15 * 22.6 / 17
19.9412
As a lot of commands output values, you can pass the output to another command. Here,
PenColour returns the number of the current pen colour, and SetPenColour sets it to a new value,
one greater than the old value:
PenColour
1
SetPenColour PenColour + 1
PenColour
2
Minus Signs
You might think that a minus sign is just a minus sign, but actually there are two flavours:
Unary Minus
-7 5-4
Binary Minus
Unary minus is part of the number. Binary minus is an operator which has two numbers as its
11
arguments.
It's important that Logo can tell the difference easily. Imagine we've created a procedure called
Proc1 which takes two numeric parameters. What are the parameters in this call?
Proc1 5 -4 -3
Is 5 the first parameter, or the result of 5 - 4? What is the second parameter? -3 or the result of
-4 - 3. Or have I mistakenly specified three parameters?
For these reasons, unary minus has to be immediately followed by a number with no
intervening space, and binary minus has to have a space between it and the following number.
12
The Turtle
Before diving deeper into graphics, we need to understand the Turtle and how its status affects
drawing in the Graphics window. The most important thing about its status is its location, and to
understand that we need to look at the Canvas.
The Canvas
The Canvas is the Graphics window with all the gubbins — scroll bars, title bar, etc — taken
away. Itʼs where the turtle draws.
Imagine the canvas as a piece of graph paper.
y axis
+y
Origin
(0,0)
x axis
-x +x
-y
Half-way down the canvas is an imaginary horizontal line going from left to right — the x axis.
This is used to measure the distance across the canvas. The position half-way along the x axis has
an x-value of zero. Positions to the right have progressively larger values; positions to the left have
progressively smaller values.
Half-way across the canvas is an imaginary vertical line going from bottom to top — the y axis.
This is used to measure the distance up and down the canvas. The position half-way up the y axis
13
has a y-value of zero. Positions above this have progressively larger values; positions below it
have progressively smaller values.
The axes (plural of axis) meet in the middle, where they both have a value of zero. This is
called the origin. Any point on the canvas can be specified by stating its x and y values in the form
(x,y). The x and y values are know as the pointʼs co-ordinates. So the origin has co-ordinates of
(0,0).
Letʼs zoom in a bit closer and look at a couple of arbitrary points on the canvas. Weʼll call them
Point A and Point B, shown by red circles in the diagram:
y axis
Point B
61
177 Point A
87
69
x axis
Remember, where the x- and y-axis cross, the values of x and y are zero. All along the y axis,
the value of x is zero, and all along the x axis, the value of y is zero. Point A is 87 pixels to the right
of the y axis, so its x co-ordinate is 87. It is 69 pixels up from the x axis, so its y co-ordinate is 69.
Point A is therefore at (87,69).
Point B is 61 pixels to the left of the y axis, so it has an x co-ordinate of -61. It is 177 pixels
above the x axis, so it has a y co-ordinate of 177. Point B is therefore at co-ordinates (-61,177).
You can change the size of the Canvas (and therefore the Graphics window) using menu
Special/Canvas Size… — youʼll then get prompted for the new width and height; or with the
command SetCanvasSize. For instance SetCanvasSize [600 480] will give you a canvas which is
600 pixels wide and 480 pixels high.
14
this point. As the Turtle moves around the Canvas in response to your commands, its position
changes, but it always knows where it is, and you can query its current position by issuing some
commands:
Co-ordinates in a list
Position
[100 80]
XPos x co-ordinate
100
YPos
80 y co-ordinate
The Turtleʼs position changes when you issue Forward or Back commands, but you can set the
Turtleʼs co-ordinates explicitly with these commands:
SetPosition [ x-co-ordinate y-co-ordinate ]
SetX x-co-ordinate
SetY y-co-ordinate
The Home command, like Clearscreen, moves the Turtle to the origin, but without clearing the
screen.
0 degrees
180 degrees
When the Turtle turns right (clockwise), the heading increases; when it turns left (anti-
clockwise), the heading decreases. This doesn't look quite right in the diagram above, because
turning left 90 degrees from a heading of zero gives a heading of 270. If you subtract 90 from zero,
15
you get -90 — but we always specify the heading as being between zero and not-quite 360, so if
you have a negative heading, just keep adding 360 to it until itʼs zero or above.
Similarly, going right 90 degrees from a heading of 270 degrees you might expect to give a
heading of 360 degrees — but again, the heading is always specified as being less than 360
degrees, so if you get a value of 360 or above, just keep subtracting 360 until you get less than
360.
The following diagram shows a turtle tilted 30 degrees to the right from the vertical (blue
arrow), so it has a heading of 30 degrees.
0∘
Head
ing 30 ∘
5
14
R
t
ig
ef
ht
L
40
70 ∘
245 ∘
If it turned another 40 degrees to the right (red arrow), it would have a heading of 30 + 40 = 70.
If instead it turned 145 degrees to the left (green arrow), it would have a heading of 30 - 145 =
-115. But remember we always give the heading as between zero and just less than 360, so the
heading is -115 + 360 = 245.
Visibility
The Turtle can be hidden with HideTurtle — This can make it easier to see what youʼve drawn.
It can be shown again with ShowTurtle. Shown? lets you query the Turtleʼs visibility.
16
The Pen
What does the Turtle draw with? — A pen of course! The concept of a pen is used to hold the
attributes that affect the lines drawn by the Turtle. The Pen is considered to be right in the middle of
the Turtle.
Up or Down?
When we move the Turtle, we usually want it to draw a line, but sometimes we just want to
move it to a new position without doing any drawing. To do that, we ʻlift the Pen off the paperʼ so
that it doesnʼt draw anything. The command to do that is PenUp. After a Penup, no lines will be
drawn until you issue a PenDown.
Pen Colour
Drawing everything in black would be pretty dull, so we can change the Penʼs colour — the
colour it draws lines with — using SetPenColour, which takes a single numeric parameter. So what
does SetPenColour 3 mean? What colour is 3? Here, the 3 is not a colour in itself, but an index
into a list of colours.
PenColour returns the current Pen colour. Pen returns a list containing the Penʼs state (PenUp
or PenDown) and the Pen colour, and SetPen sets these attributes from a list.
Pen Width
You can change the width of the line the pen draws to get thick or thin lines. SetPenWidth can
be used to change the width of the pen from less than a pixel to bigger than the canvas.
17
SetPenWidth 1 Forward 60
SetPenWidth 10 Forward 60
SetPenWidth 50 Forward 60
SetPenWidth 100 Forward 60
SetPenWidth 200 Forward 60
18
Datatypes and Variables
We've already seen the use of numbers in Logo — usually we pass them to a command such
as Forward. In this section weʼll look a bit more at numbers and what we can do with them; then
we'll look at the other datatypes that Logo can handle — words and lists. Finally we'll look at
variables which can hold the values of numbers, words, and lists.
Numbers
There are two types of number in Logo — whole numbers (integers) and floating-point
numbers (real numbers, numbers with a decimal point). Logo can convert between them, so you
don't need to worry about what sort of number you've got.
Something to watch out for — if you've got a number between 0 and 1, let's say 0.7 — you
have to keep the leading zero: Logo won't accept .7 as a number.
Operations on Numbers
You can use the usual arithmetic operators:
+ multiplication
- subtraction
/ division
* multiplication
You can just enter an arithmetic expression in Logo and the program will evaluate it (output in
blue):
5+6
11
12.3 * 100
1230
10 / 3
3.33333
6-4
2
5+6*3
23
(5 + 6) * 3
33
A couple of things to note here – Logo follows the usual rules for operator precedence:
multiplication and division have a higher precedence than addition and subtraction. This means
that * and / are evaluated before + and -, so in the fifth example above, 6 is multiplied by 3 first,
then 5 is added to the result. If you want the addition to happen first, you need to use parentheses
19
(as in example 6).
The other thing to note is that when the minus sign is used in subtraction, as in example four
above, there needs to be a space between it and the second operand. Otherwise this would look
like a negative number, -4.
Relational operators
These are used in comparisons. They return the value true or false depending on the
comparison:
5<6
true
5>6
false
3=3
true
4=3
false
Not 5 < 6
false
Not 5 > 6
true
Not 3 = 3
false
Not 4 = 3
true
We will see the importance of the relational operators in the chapter Command and Control.
Mathematical Functions
There are a whole load of trigonometric functions: Cosine, Sine, Tangent, ArcCosine,
ArcSine, ArcTangent - and their hyperbolic versions: Cosh, Sinh, Tanh, ArCosh, ArSinh, ArTanh.
20
Abs Output the absolute value of a number
Exp Returns e to the power of the input number
Integer Truncates the input number to its whole number portion
Log Returns the natural logarithm of the input number
Log10 Returns the base-10 logarithm of the input number
Pi Outputs the value of Pi
Power Returns parameter1 to the power of parameter2
Random Returns a random integer between zero and the input number
Remainder The remainder when parameter1 is divided by parameter2
Round Round the input to the nearest integer
Sqrt Output the square root of the input number
Some examples:
Abs -11
11
Integer 1.8
1
Round 1.8
2
Pi
3.14159
Random 10000
432
Power 10 3
1000
Log10 1000
3
Sqrt 225
15
21
Words
A word is just a sequence of characters. All these are words:
Herbert
schizoid
xyz
too much!!!
456
When you specify these to Logo, you must precede the word by a double quote character(").
This signifies to Logo that the sequence of characters is a word, rather than the name of something
like a function or variable.
In other programming languages, these are known as strings, and I will sometimes refer to
them as such.
When you specify a word, Logo needs to know where it ends. When it comes across a space,
or end of line, or an operator such as a plus sign, it terminates the string there. The trouble is that
sometimes we want the word to contain a space or other delimiting character. We can get round
the problem by using an escape character, the backslash (\).
Here are some examples:
"QWERTY
QWERTY
"Too\ hot
Too hot
"A\ backslash\ looks\ like\ this\ \-\ \\
A backslash looks like this - \
Weʼll see later that itʼs easier to use lists to get around the problem.
Operations on Words
The arithmetic operators don't work with words, but the relational operators do:
"abc = "abc
true
"abc < "xyz
true
"abc < "ABC
false
22
Count "QWERTY
6
Count "Too\ hot
7
Empty? "abc
false
Empty? "
true
First "QWERTY
Q
ButFirst "QWERTY
WERTY
Last "QWERTY
Y
ButLast "QWERTY
QWERT
Item 3 "QWERTY
E
Then we have functions for constructing new words from other words:
23
(Word "ABC "DEF "GHI "JKL "MNO)
ABCDEFGHIJKLMNO
(Word "Too "Much "Too "Young)
TooMuchTooYoung
Word? "ABC
true
ASCII "a
97
Char 97
a
LowerCase "ABC1234\ abZ
abc1234 abz
UpperCase "ABC1234\ abZ
ABC1234 ABZ
Member? "a "ABC1234\ abZ
true
Note that for Member?, this only works when the first parameter is a single character.
24
Lists
A list is like a word in that it is a sequence of objects, but whereas a word consists of
characters, a list can contain a number of different objects – words, numbers, or even other lists.
When you represent a list in Logo, you surround it with square brackets.
All of these are lists:
[A B C]
[1 2 3 4]
[abc def ghi jkl]
[1 27 [56 45] [12] [[v] g]]
[]
[c d * / "]
Operations on Lists
The only relational operator you can use is the = operator (less than and greater than donʼt
make much sense for lists). Try these examples:
[A B C] = [ A B C ]
true
[a b c] = [[a] [b] [c]]
false
Not [a] = []
true
A lot of the functions we saw used with words also work with lists:
25
FirstPut Makes the first input the first member of the second input
LastPut Makes the first input the last member of the second input
Instead of the function Word used to construct words, we have a couple of functions to help
construct lists, List and Sentence. These examples show the similarities and differences:
As you can see, Sentence strips off the outer brackets of the objects before it puts them into the
list.
Just one more list function, List?. This outputs true if its parameter is a list:
26
Variables
Up to now, all the values we've been inputting to functions have been literal values or literals.
Like all other programming languages, Logo can hold a value in a variable. A variable can
hold any type of value – a number, word, or list, or even a boolean (true or false) value.
The two things we can do with a variable are set its value (assignment) and get its value.
You need to give the variable a name – don't have spaces or any other odd characters in the
name and don't start it with a number.
To create a variable myNumber and set its value to one:
Make "myNumber 1
Then to get its value back:
:myNumber
Note that when setting the variable, we use " , when getting its value, we use :.
To increase the value of myNumber by one:
Make "myNumber :myNumber + 1
I can pass the value of myNumber to a function as if it was a literal number:
SqRt :myNumber
I can, if I like, then set the variable myNumber to contain a different type of object, such as a list
or a word:
Make "myNumber [abc def]
Make "myNumber "thingie
So a variable can be used to pass a value to a function. There is though, a situation where that
doesnʼt work. Remember the function SetPosition which sets the position of the Turtle from its
parameter, a list of two numbers. We can try and pass variables to it:
make "x 20
make "y 50
SetPosition [:x :y]
SetPosition needs a list of two numbers
Remember that when you put things in a list, they appear in the list in exactly the same form as
you wrote them, so the first member of the list is not 20, but the word :x . This is easily
demonstrated:
[:x :y]
[:x :y]
List :x :y
[20 50 ]
27
So this can be passed to SetPosition:
SetPosition List :x :y
28
Flow Control
So far, we've been issuing single commands, or a number of commands one after the other in
a block, like this sequence of commands to draw a square (Fd is short for Forward and Rt is short
for Right):
Fd 150 Rt 90 Fd 150 Rt 90 Fd 150 Rt 90 Fd 150 Rt 90
In this tutorial we'll be looking at some commands which will make it easier to issue repeated
sets of commands and a command for deciding whether to issue a command.
Repeating Commands
The example above has two commands (Fd 150 Rt 90) repeated four times. Rather than have
to write them out four times, we can use this construct:
Repeat 4 [Fd 150 Rt 90]
Repeat takes two parameters — a number and a list. The number specifies how many times
the commands in the list are to be executed.
We can build up complex patterns using Repeat. Here we've got an inner Repeat drawing the
box as before, while an outer Repeat draws the box 12 times, rotating through 30 degrees each
time:
CS Repeat 12 [Repeat 4 [ Fd 150 Rt 90 ] Rt 30]
29
and here's a variation on the last pattern:
CS Repeat 12 [Repeat 4 [ Fd 150 Rt 90 ] Fd 30 Rt 30]
Often when you're looping like this, you want to keep a count of what iteration of the loop
you're on. You can use a variable to do this. Say you want to print the first ten numbers. First you
initialise your variable:
Make "myNumber 1
Then Repeat the commands which will print the value of the variable and increment the
variable:
30
Run
For the case where you just want to run the commands in the list once, there is the Run
command. For example:
Run [ ClearScreen Fd 200 ]
This looks like a fairly useless command — why not just run the commands in the list?
The power of this is that you can build a list of commands, store them in a variable and then run
the list later:
Make "cmd [ ClearScreen SetPenWidth 20 Fd 200 ]
Run :cmd
Making Decisions
Logo has the IF statement to decide what action to take depending on whether a condition is
satisfied. An IF statement looks like this:
IF condition [true statements] [false statements]
The condition is an expression which returns true or false. We've seen examples of these sort
of statements already:
5>6
false
Empty? [ ]
true
"the\end = Word "the "end
true
Of course, normally you'll be comparing the values of variables rather than literals to literals.
If the condition is true, the first list is executed, otherwise the second list is executed. Here's an
example:
Make "amount 20
if :amount < 30 [print "small][print "big]
small
Thatʼs It?
We seem to be missing a few constructs that are available in other programming languages:
while, for, repeat until. There's no equivalent in the Logo language, but you can get the same
effects using procedures - see the Using Procedures chapter.
31
Or something more angular:
Make "amount 10
CS Repeat 180 [Fd :amount Right 90 Make "amount :amount + 8]
I can multiply amount by -1, making its sign alternate between a negative and positive value.
Going right by a negative amount means going left:
Make "amount 4
CS Repeat 40 [Repeat 40 [Fd 1 Right :amount ]Make "amount :amount * -1]
32
Procedures
Procedures are a means of making your logo code easier to understand by grouping a series
of commands together. Itʼs a bit like creating your own commands.
Letʼs consider drawing a square. To create one with a side of 300 pixels, we could say:
repeat 4 [forward 300 right 90]
or to use abbreviations:
repeat 4 [fd 300 rt 90]
If I then want to make a pattern from the squares by rotating in a circle, I get:
repeat 36 [repeat 4 [fd 300 rt 90] rt 10]
Things soon start to get difficult to understand. To make it simpler, Iʼll make my commands to
draw a square into a procedure called box, so whenever I call box, Iʼll get a square drawn.
On the left is a list of the procedures you've got defined. Currently there is none. We're going to
create a new one, so click on the New button:
33
An entry is added to the list and assigned the name newproc1. Overtype this with the name box
and press return. Type the box-drawing commands in the main text area:
34
Note that the name of the procedure is blue because the procedure has been changed
(created actually) but has not been applied. Press the Apply button to make the changes available.
We can now call the box procedure (after clearing the screen). Issue this command:
cs box
to invoke the commands in the procedure box.
The command to draw all the squares in a circle now becomes:
cs repeat 36 [box rt 10]
which is a bit easier to understand.
Parameters
The box procedure isn't very good if I need boxes of different sizes. Go back to the procedures
window, click on the Add button next to the Parameters list box, and overtype param in the list box
with the word size. You may need to double-click on it.
This will be our parameter, and is like a variable (I could have called it anything, but this is
meaningful). Change the body of the procedure to refer to the parameter:
repeat 4 [fd :size rt 90]
Note that the name of the procedure has become blue because we've made some changes.
Click on the Apply button to activate them.
Now to create a square of say, 150 pixels:
cs box 150
and our 'rotating square' command becomes:
35
cs repeat 36 [box 150 rt 10]
We can now use a variable to change the size of the box as we go:
cs make "amount 30
repeat 36 [box :amount rt 10 make "amount :amount + 10]
Comments
You can add comments to your procedure to remind yourself of what it does. Precede your
comments with a double-slash like so:
Note that comments appear in green, numbers are blue, and other text elements are coloured
to make it easier to read what's going on. If you don't like it, you can turn off this syntax coloration in
preferences.
Local Variables
You can declare a local variable in a procedure using the local keyword. This variable is
known only inside the procedure, but otherwise can be treated like other (global) variables:
local "lvar
make "lvar 10
make "lvar :lvar + 1
If there is a global variable of the same name, this is masked by the local variable whilst inside
the procedure. This stops the procedure from changing variables external to itself which just
happen to have the same name as its local ones. Using local variables is good practice as it saves
a procedure having unwanted side-effects.
Outputting Results
You can return a value from a procedure. Create a new procedure called TimesTen. Give it a
parameter called num. Make the body of the procedure:
output :num * 10
The procedure should output the value of the input number times ten. Try it out:
TimesTen 50
You should get the value 500.
Recursion
A procedure can call itself.
Let's consider the mathematical function factorial. factorial(4) gives the result of 4 x 3 x 2 x 1.
factorial (5) gives 5 x 4 x 3 x 2 x 1, etc. factorial (0) returns 1.
36
Stating this recursively, factorial(0) = 1, factorial(n) = n * factorial(n-1)
To implement this, create a new procedure called factorial. Give the procedure a parameter
called num, and make the body of the procedure:
if :num = 0 [output 1] [ output :num * factorial :num - 1]
If the input parameter is zero, factorial returns 1, otherwise it returns the input number times
the factorial of the next number down.
Try these:
factorial 3
factorial 0
factorial 10
factorial 5
37
make "a 55
while [:a > 50] [print :a make "a :a - 1]
So let's have a go at creating a for procedure. We want it to look like this:
for variable-name start-value end-value [actions]
so a call might look like this:
for "i 1 10 [print :i]
so the procedure would set the variable i to 1, 2, 3, etc., up to 10 and for each of those values
would print the variable.
So create a procedure called for with parameters var, start, finish, and actions.
The first thing the procedure must do is set the variable i to the value of the start parameter.
Since the name of the variable is held in the var parameter, this is easy:
make :var :start
Then we need to test if we've finished in an if statement:
if NOT :start > :finish
[
Run :actions
for :var :start + 1 :finish :actions
]
[
]
If we haven't finished, we run the actions, then call the for procedure recursively with start
incremented by 1.
Apply the procedure then try this:
for "i 1 10 [print :i]
Thing
Consider a procedure which will make some change to a variable — let's call it increment.
When we pass the name of a variable to it, it increases the value of the variable by 1. So:
make "i 20
increment "i
would set variable i to 21.
Set up a new procedure increment with an input parameter called var.
For the body of the procedure, we can't say:
make :var :var + 1
because that would evaluate to:
make "i "i + 1
What we need is some way to get the value held by the variable whose name is held by var.
Logo provides a function, Thing, to do just that.
Make :var (Thing :var) + 1
38
Thing and its argument need to go in parentheses otherwise Logo tries to add 1 to :var first.
Importing Procedures
If you've procedures in one Logo document that you want to copy into another, you can simply
drag and drop from one document into another.
Select the procedures you want to copy, then drag them into the procedures window of the
other document.
39
Graphics
Weʼve already covered the basic drawing commands in earlier chapters — Forward, Back,
Right and Left. The chapter on the Turtle covered the Turtle, the Canvas and x- and y-co-ordinates,
and the Pen. Weʼll cover some further graphics topics in this chapter.
Colours
There are two ʻcurrentʼ colours that drawing can take place with — the Pen Colour, or
Foreground Colour, which is used for almost all drawing commands, and the Background Colour,
which is used to fill the Canvas when you issue Clean or Clearscreen.
You can see what these are set to by issuing the PenColour and Background commands:
PenColour
1
Background
0
The numbers you get back donʼt tell you much about what the colours actually look like. They
are not colours themselves, but indexes into a colour list:
The colour of each entry in the colour list is specified by how much red, green and blue it
contains. So a completely red colour contains 100% red, no green, and no blue. A turquoise-ish
colour might contain no red, 60% green, and 60% blue, while black contains no red, green, or blue.
Because all colours are specified in terms of red, green, and blue, this system is known as the
RGB system. In ACSLogo, rather than specify amounts as percentages, you specify them as a
number between zero and one. So the RGB values for the red colour would be (1.0, 0.0, 0.0), and
40
for the turquoise-ish colour (0.0, 0.6, 0.6). Black is (0.0, 0.0, 0.0).
Here are some examples of colours and their RGB values.
Colour R G B
So, if I want to draw a line in red, I set the Pen colour to 2 by issuing SetPenColour 2, and if I
want to set the canvas to black, I issue SetBackground 1 and ClearScreen.
What if a colour I want is not in the list? Thatʼs easy enough — just set one of the list entries to
the RGB values you require using SetRGB, which takes two parameters, a colour number and a
list of RGB values:
SetRGB 3 [1.0 0.7 0.7]
This particular example sets pen colour 3 to pink. You then need to issue SetPenColour 3 to
use it for drawing, or SetBackground 3 and ClearScreen to fill the canvas with it.
You can query the RGB values for a colour number using command RGB:
RGB 3
[1 0.7 0.7]
The parameter is the colour number. It returns the red, green, and blue values.
41
second diagram, Iʼve covered it in strips of an increasingly opaque red colour.
On the left-hand side of the second diagram, the red colour has an opacity of 0.0 – none of the
red colour can be seen. It has been set with the command SetRGB 2 [ 1.0 0.0 0.0 0.0] – the fourth
entry in the list is the opacity. For the next strip, list values are [ 1.0 0.0 0.0 0.1], then [ 1.0 0.0 0.0
0.2], until at the right-hand side, the red colour is completely opaque ([ 1.0 0.0 0.0 1.0]) and none of
the picture below it shows through. If you give SetRGB three values, Logo assumes that you want a
colour that is completely opaque.
Drawing Arcs
The Arc command is used to draw circles or parts of circles.
The position and heading of the turtle affect what is drawn. The arc is drawn centred on the
turtle's position, starting from a point directly ahead of the turtle, sweeping clockwise. The command
takes two parameters, an angle and a radius. Angle is the angle through which the arc is drawn,
360 being a full circle.
Angle
Left 60
Arc 100 200
Radius
Angle
Radius
Note that Arc does not affect the heading or position of the Turtle.
42
Text
Text is drawn by using the GraphicsType command. The command takes a single parameter
which can be a word or a list.
The text is drawn at right-angles to the turtle heading.
You set the size of the characters drawn using SetTypeSize. These commands demonstrate
the sort of thing you can do:
zero degrees
SetTypeSize 24
45
90 degrees
GraphicsType [ zero degrees]
de
Right 45
GraphicsType [ 45 degrees]
gr
Right 45
ee
GraphicsType [ 90 degrees]
s
You can also change the font used by GraphicType. The command Fonts gives a list of fonts
available. You can then use any of these entries with SetFont to change the current font:
SetFont [AntiqueOlive-Compact]
The TextBox command outputs a list describing the size of its parameter if printed by
GraphicsType. The list is of the form [x y w h], where x,y is the co-ordinate of the bottom-left corner,
w is the box width, and h is the box height.
The textbox is not a bounding box - the height of the box is the line-height of the text, and the
width includes letter spacing on either side.
Filling Shapes
The squares and other shapes we drew in earlier chapters have been empty – weʼve just
drawn the outline. So how do we fill a shape with colour?
There are two standard Logo commands, Fill and Fillin.
In the following diagram, Iʼve drawn a square in blue (Pen colour 3) inside a red square (Pen
Colour 2). the Turtle is at the centre of both squares.
43
Pen Colour 2 (current Pen colour)
Pen Colour 3
Fill
Fillin
The current Pen colour is set to 2. If the fill command is issued, it keeps filling (from the current
position under the turtle) until it hits a boundary of the current Pen colour — it ignores the inner
square which is colour number 3.
Fillin keeps filling until it hits a border which is a different colour from the starting pixel (the one
at the turtle position).
There are a couple of problems with these two methods of filling. First, what is filled does not
depend just on the shape you've just drawn, but depends on what is on the canvas already, which
may be all sorts of stuff depending on what you've been drawing.
The second problem is to do with the way Mac OSX draws lines. To get the beautifully smooth
lines and text that you see in OS X, edges of lines can be drawn in a slightly different colour from
the colour that you asked for. This makes the lines appear smoother to the eye (and brain). This
technique is known as anti-aliasing. It means that the Fill command especially may not recognise a
thin border when it hits it.
We'll look at alternative ways to do fills in the Paths chapter.
44
Shadows
The SetShadow command sets a dropshadow for all subsequent drawing.
S
ClearScreen
SetShadow [10 -15 5]
SetTypeSize 324
SetPenColour 2
GraphicsType "S
Here the SetShadow command makes the shadow drawn be offset 10 pixels to the right, 15
pixels down, and with a blur radius of 5 (the blur radius is a measure of how much the dropshadow
is spread). You can add a fourth parameter - pen colour, which specifies which colour to use as the
shadow colour.
S
ClearScreen
SetShadow [10 -15 5 3]
SetTypeSize 324
SetPenColour 2
GraphicsType "S
To stop any more shadows being drawn on subsequent drawing, call SetShadow with the
empty list:
SetShadow [ ]
45
Images
The DrawImage command draws an image from an image file.
Right 30
DrawImage [~/IMG_0014.JPG] [300 200]
The image is drawn at the turtle position, tilted by the turtleʼs heading. The first parameter is the
path of the image file in the file system (here the tilde (~) means the current userʼs home directory).
The file name usually has to be put in square brackets because it often contains a slash (/), which
Logo interprets as a division sign. If the name it doesnʼt contain slashes, spaces, or other
characters which have special meaning to Logo, it can be quoted as a string.
The second parameter to DrawImage is a list of up to two numbers. If the list has two numbers,
the first is interpreted as width and the second as height - the image is drawn with those
dimensions. If the second number is missing or is zero, the height is derived from the width,
maintaining the imageʼs aspect ratio. If the first number is zero and the second is not and is
present, the width is derived from the height. If both numbers are missing or zero, the image is
drawn at itʼs ʻnaturalʼ size.
46
Paths
We saw in the Graphics Chapter that the Fill and Fillin commands often don't give you what
you want — they fill pixels based on what is already on the canvas.
I've added to ACSLogo a non-standard command called FillCurrentPath. This command
doesn't care what is on the canvas already. It just tries to fill the last shape drawn. To understand
exactly what it does, we need to understand the concept of the current path.
When you draw a line (using Forward, Arc, etc.), ACSLogo adds the line to the current path,
which is just a list of the lines draw. The command CurrentPath returns the contents of the current
path as a list of lists:
ClearScreen
Forward 200
CurrentPath
[[moveto 0 0][lineto 0 200]]
The ClearScreen command caused whatever was in the current path to be cleared, and made
the Turtle move to x co-ordinate zero, y co-ordinate zero. At this point, nothing has been draw, so
the current path is still empty. The Forward command made the Turtle move from co-ordinates (0,0)
to (0,200). This generated the moveto and lineto entries in the current path.
As long as the pen stays down (so drawing is done), entries are added to the current path:
Right 90
Forward 100
CurrentPath
[[moveto 0 0][lineto 0 200][lineto 100 200]]
PenUp
CurrentPath
[]
FillCurrentPath
The main point of keeping a current path is to be able to fill the shape you've just drawn easily.
After drawing, say, a rectangle, you can just issue FillCurrentPath and it will fill the shape in the
current pen colour. With Fill and Fillin, you have to position the Turtle somewhere in the middle of
the shape after drawing it before issuing the command.
47
StrokeCurrentPath
You can also issue StrokeCurrentPath to draw a line around the path with the current pen
width and pen colour.
Saving Paths
Because the current path is just a list, you can save it in a variable:
This can then be used in StrokePath and FillPath which are similar to their current path
equivalents, but each takes a path as parameter. The value of this can be seen in the next section.
Text
When you draw text using GraphicsType, the text is added to the current path. By saving it in a
variable, we can get some interesting effects. First letʼs draw a big letter and save it in the current
path:
SetPenColour 1
ClearScreen PenUp
SetPosition [-150 -150] PenDown
SetTypeSize 400
GraphicsType "S
make "p CurrentPath
If we issue ClearScreen, it clears the current path, but we have the path saved in a variable
which we can fill and then stroke to get an outlined letter:
48
ClearScreen
SetPenColour 2
FillPath :p
SetPenWidth 11
SetPenColour 1
StrokePath :p
I can then add a further dash of interest by stroking with a dashed white line:
SetLineDash [0 20 20]
SetPenColour 0
SetPenWidth 9
StrokePath :p
49
Holes
When you look at the letters that make up words, such as the one below:
Pogo
you can see that some letters contain ʻholesʼ. Letters are just filled paths. The letter ʻoʼ, for
instance, is just a small ellipse inside a bigger one. When the bigger ellipse is filled, why doesnʼt
that just fill in the smaller ellipse as well?
Letʼs look at simpler shapes — rectangles — and try a few things out. First I draw a rectangle
and save the path in a variable called bigrect:
SetPenColour 1
Repeat 4 [Forward 150 Right 90]
Make "bigrect CurrentPath
Then I move in a bit and draw a smaller rectangle and save its path in a variable called
smallrect:
50
PenUp SetPosition [40 40] PenDown
Repeat 4 [Forward 70 Right 90]
Make "smallrect CurrentPath
Next I join the two paths together with the Sentence command, which joins two lists – this is to
make the two paths into one object – then fill the path and stroke it:
You can see that the fill has just filled in both rectangles - there's no ʻholeʼ. This time Iʼll draw
the small rectangle in a different way — first Iʼll go right, then draw the rectangle going anti-
clockwise:
This time weʼve got the hole — so holes in overlapping shapes are dependent on which
directions their paths ʻwindʼ.
51
You can see the directions of the paths in this diagram:
The outer rectangleʼs path goes clockwise, the inner one anticlockwise.
This nesting can go on indefinitely, with each path going in the opposite direction to the one
outside it:
The path is accumulated in a variable called a1. Each iteration through the loop, its direction is
reversed using command ReversePath, and itʼs concatenated with the current path (which is the
arc just drawn). This means that we end up with a path of circles, each going in the opposite
direction to the previous one.
Overlapping objects so that one does not lie entirely within the other gives us more scope for
creativity.
52
The complications in the code are mostly due to positioning prior to drawing the square and
the circle, as I want them offset from the canvas origin and from each other. Also, Iʼve deliberately
used relative commands to do the positioning (Left, Right, Forward, Back) rather than absolute
commands (SetPosition, SetHeading).
To simplify following code, Iʼve put all that code in a procedure called shape and replaced the
last three lines with Output Se :a1 :a2. So the procedure outputs the path and doesnʼt draw it.
In the following diagram, the drawing on the left shows the result of stroking the output from the
shape procedure. For the middle drawing, shape is called again after the Turtle has turned left 30
degrees. For the last drawing, that has been repeated another ten times.
Make "p [ ]
Repeat 12
[
Make "p Se :p shape
Left 30
]
ClearScreen
SetPenColour 2 FillPath :p
Reversing the path each time through the loop gives us some more interesting holes:
Make "p [ ]
Repeat 12
[
Make "p Se ReversePath :p shape
Left 30
]
ClearScreen
SetShadow [ 15 -15 11 ]
SetPenColour 2 FillPath :p
SetShadow []
SetPenColour 1 StrokePath :p
53
Note that I've added a shadow before doing the fill — this helps show that the holes are really
holes and not just white-coloured bits of the pattern.
54
Vector Graphics
The paths we've been talking about are examples of vector graphics — they store the image
as a collection of lines (straight and curved) rather than as tiny rectangles of colour (pixels) which
bitmap images are stored as.
The advantage of a vector-based image is that it can be magnified indefinitely without loss of
quality – with a bitmap-based image, the more you magnify it, the more you will see the pixels
making it up – like sticking your face against a TV screen. If youʼre viewing this from a PDF file on a
computer, you can see this for yourself by looking at these seemingly identical images:
Zoom in on the page using the zoom button in the program youʼre viewing this with. Keep
zooming in , and after two or three zooms, you should see that the image on the left starts to look
pixellated, while the one on the right remains sharp. The left-hand image is a bitmap, while the one
on the right is a vector graphic.
in this paragraph.
See how much better quality the zoomed vector graphic image is.
55
ClearScreen command. When these are exported, the image is subtly different from the image on
the canvas. Just like when using StrokePath and StrokeCurrentPath, line-joins will be neater,
and the results of Fill and FillIn commands will not be exported.
56
Clipping Paths
So far weʼve been accustomed to all of our drawing appearing on the canvas, as long as we
draw within the bounds of the canvas. The edges of the canvas ʻclipʼ any drawing you do, so that
nothing is drawn outside of it. We can actually use other shapes to clip our drawing - in fact we can
use anything which can be expressed as a path, such as a letter or circle:
In the first example, the clipping path is created by drawing a large letter A, then saving the
current path in a variable:
SetFont [Times-Bold]
SetTypeSize 400
PenUp SetPosition [-160 -70] PenDown
GrType "A
Make “savep CurrentPath
The path description of the letter A has been saved in variable savep. First Iʼll use it to draw the
blue background:
SetPenColour 3
FillPath :savep
Then I set the clipping path using command SetClipPath. The command takes a single
parameter — the path I saved before:
SetClipPath :savep
Then I can draw whatever I want, and it will all be clipped to the clipping region. For the
example above, I used the heppel procedure from the examples file in the ACSLogo download
folder. I used pen colour 4.
To turn off the clipping path, call SetClipPath with an empty list as its parameter:
57
SetClipPath [ ]
SetPenColour 2
StrokePath :savep
The example on the right was done in a similar way — the circular clipping path was drawn
using the Arc command, and the internal pattern was drawn using the PeanoX procedure from the
examples file in the ACSLogo download folder.
58
Files
In this tutorial, I'll be looking at how you can read from and write to files within ACSLogo. You
need a fairly basic understanding of the OSX file system — how files exist within directories, that
sort of thing.
There are two types of commands that deal with files — file manipulation commands, which
are used to open, read and write files, and file management commands, which give you
information about the file system and let you change your location within it. We'll cover the latter
commands first.
pwd
/Users/alan/Documents
See what happens when you issue the command— you should get something different.
Since pwd is just outputting a string, you can store it in a variable:
To change your position within the file system you can use the CD (change directory)
command. CD takes one parameter, which can be a string or a list.
Consider the following file system. At the moment, the current directory is /Users/alan/
documents:
59
/
Users
alan
Documents Movies
Users
alan
Documents Movies
If I now issue:
CD "Movies
my current directory changes to Movies:
60
/
Users
alan
Documents Movies
Rather than go up and down the directory hierarchy incrementally, I can specify a complete
path — say I want to move to the Documents directory, the full path is /Users/alan/Documents. If I try
and give that as a parameter to CD, I get an error:
CD "/Users/alan/Documents
unknown function Users
This is because the / character, which is used to delimit directory names, is interpreted by the
ACSLogo parser as a divide operator. To get the full pathname input to CD without being tampered
with, I need to put it in a list:
CD [/Users/alan/Documents]
pwd
/Users/alan/Documents
Another useful thing to know is that as shorthand for the home directory (in my case /Users/
alan), you can use a tilde (~). This can be used on its own or as part of a path:
CD [~/Movies]
pwd
/Users/alan/Movies
If you give CD an empty string or empty list as input, it will make the home directory the current
directory:
CD "
pwd
/Users/alan
All this typing is a bit un-maclike. To save some time, you can drag a directory from a finder
window into the ACSLogo Main window. The full pathname of the directory is pasted into the
document, and you can wrap it in brackets and put CD in front of it.
These are the steps:
61
1. From a finder window, drag a folder over the ACSLogo Main window:
2. A cursor will appear. Position it where you want to drop the directory name, and press
Control:
3. Release the mouse button, and the full path name will appear:
62
To see what files are in the current directory, use the Dir command. This lists the files one per
line. So that you can distinguish directories, each one is followed by a /:
pwd
/Users/alan/Documents
Dir
.localized
dabsOrder.pdf
DVLA/
edp24.pdf
Einstein.doc
Einstein.pdf
FAXstf X User Data/
file1.graffle
Installer Logs/
Microsoft User Data/
ms.pdf
YarisRegistration.jpg
63
Let's look at writing to a file first.
To open a file for writing, issue OpenWrite. This takes a parameter which can be a string or a
list:
OpenWrite "testlogo.txt
Issue the command above to open the file in the current directory.
There are a number of commands for writing data into the file. These are all variations of
commands we've seen already, prefixed by an F:
FPrint
FType
FShow
Let's write some data to the file. Issue these commands:
FPrint [the end]
FPrint [of the world]
FPrint [is nigh.]
Then we need to close the file. Issue this command:
CloseWriteFile
Now go into the OSX Finder and find the file testlogo.txt. If you double-click on the file, it
should open in TextEdit. Check that the contents match the FPrint statements above.
So much for writing to a file. Now we'll try reading from one. We'll use the file we've just written.
To open it, issue:
OpenRead "testlogo.txt
To read a line from the file into a word, issue:
FReadWord
To read a line from the file into a list, issue:
FReadList
If you keep issuing FReadList, you eventually get an empty list back. To close the file, issue:
CloseReadFile
64
Movies
The algorithmic drawings we can do in logo respond very well to being animated. With
animation, we can change the items we've drawn with respect to their location, colour and shape
over time.
With examples like the Sierpinski triangle which vary according to an input parameter (level),
animation can show the variation in the triangle as the level is changed.
All animations consist of a sequence of images or frames. ACSLogo uses the Snap command
to capture each frame.
Animation in ACSLogo
The process is:
Create a new movie file
Repeat several times:
Draw an image
Snap the image
Close the movie
An Example
Let's work through an example. What we'll draw in this animation is an outlined letter. The
animation will show how the shape of the letter changes as we increase the thickness of the
outline.
The size of the each animation frame will be the size of the graphics window. It's probably too
big at the moment. Using the Special/Canvas Size… menu, set the canvas size to 400 pixels wide
and 400 pixels high.
First we need to set the size of the type. Execute this command:
SetTypeSize 250
Then letʼs try drawing a capital 'S':
GraphicsType "S
Let's move the turtle a bit to make the letter more central:
SetPosition [-100 -100]
I can do a Clean command to clear the screen without moving the turtle, then draw the 'S':
Clean GraphicsType "S
now I'm going to combine these with commands to draw the letter in colour 2, then outline it in
colour 1:
Clean SetPenColour 2 GraphicsType "S SetPenColour 1 StrokeCurrentPath
65
For the animation, I'm going to repeatedly do the strokepath while increasing the pen width
each time.
Let's start the movie. Choose Create Movie… from the Special menu and choose a location
and file name to save it to. Then complete the Compression Settings window as shown:
We'll first set a variable called pathwidth to 1, and increase it as we go through the movie. Let's
do the set-up stuff and Snap the first frame of the movie:
SetTypeSize 180
SetPosition [-205 -60]
Clean SetPenColour 2 GraphicsType "Logo
Make "pathwidth 1
SetPenWidth :pathwidth
SetPenColour 1
StrokeCurrentPath
Snap
Now we'll capture all the frames. Lets capture 60 of them. For each frame, we'll do a
StrokePath, then increase pathwidth and call SetPenWidth:
Repeat 60 [Make "pathwidth :pathwidth + 2 SetPenWidth :pathwidth
StrokeCurrentPath Snap]
Select Finish Movie from the Special menu. If you hold down the Option (alt) key, you can
select menu item Finish Movie and Open which opens the movie after saving it. Otherwise, find
your movie in the Finder and double-click on it to watch it.
66
Speech & Music
OS X has the ability to synthesize speech, and Quicktime has the ability to play synthesized
musical instruments. ACSLogo has commands which can tap into both of these capabilities. In this
chapter, itʼs a good idea to copy and paste the commands into the ACSLogo main window to try
them out for yourself.
Speech
Speech is fairly simple. You use the Say command. Give it a word or list as its parameter. in
general it's easier to use a list. Issue this command:
Say [Hello there]
You can change the voice of the speech synthesizer using SetVoice.
SetVoice [com.apple.speech.synthesis.voice.Albert]
Say [Hello there]
Issue the Voices command to get a list of available voices:
Voices
Use Voice to show the current voice:
Voice
When you issue the Say command, the command finishes straight away, which the speech is
still being said. This means that two Say commands in quick succession will cause the second
command not to be spoken, because the first is still being said. To show this, issue these two
together:
Say [The end of the world]
Say [is nigh]
To wait until the previous Say command has finished, use WaitForSpeech:
Say [The end of the world]
WaitForSpeech
Say [is nigh]
Music
Music is more complicated. the main ACSLogo command is Play.
The easiest way to approach this is to look at an example. Issue this command:
Play [1 [60 100 60]]
Playʼs parameter is a list. The first element of the list is an instrument number — in this case 1,
which is a grand piano. To get a list of the instruments available, issue this command:
Instruments
The instrument number input to Play, though, can only be a number - it can't be one of the
descriptions.
67
The second element of the list is another list, and this represents a note. The first item in the
list, 60, is the duration of the note. The time is measured in ticks, which are sixtieths of a second, so
60 ticks is one second. The second item in the list is the loudness (sometimes called acceleration
— how hard the note is hit). In this case it's 100. The maximum is 127. The third item represents the
note itself — 60 is middle C. The notes are numbered like keys on a piano keyboard, including the
black notes, so E is 64, G is 67, and C of the next octave up is 72.
To play a chord rather than a single note, add other notes to the end of the note-list:
Play [1 [60 100 60 64 67 72]]
To play the notes one after the other rather than simultaneously, each note requires its own
note-list:
Play [1 [60 100 60][60 100 64][60 100 67][60 100 72]]
To play more than one instrument at a time, group the list for each instrument into another list.
In the following example, the first instrument is a grand piano (1), the second instrument is a
woodblock (116) playing twice as fast. Select all the lines and execute:
Play [ [1 [60 100 60][60 100 64][60 100 67][60 100 72]]
[116 [30 100 60] [30 100 60] [30 100 60] [30 100 60] [30 100 60] [30 100 60] [30 100 60]
[30 100 60]]]
68
Appendix A: Menus
The ACSLogo Menu
The ACSLogo menu contains the standard OSX entries. For more details on Preferences,
see Appendix B.
69
Save To… saves a copy to another name
Export expands to a submenu - explained below.
Revert To Saved restore the document to the last saved version
Page Setup choose printing attributes
Print… print the document
Print Selection… print selected text
The Print… menu will print whichever window is frontmost, so if you want to print from the
graphics window, bring that to the front; if you want to print from the main window, bring that to the
front.
70
The Edit menu
This is the standard OSX Edit menu:
It contains all the menu items found in text editing programs such as Textedit.
The Format submenu expands to a series of menu items which relate to text formatting. These
are the same as other text-editting programs such as Textedit, so I won't go into them further here.
Canvas Size… is used to change the size of the Graphics window — a dialog is displayed
allowing you to choose a new width and height for the window:
71
The fields are initially set to the current size. Values are in pixels.
Execute is used to execute a command. It will attempt to execute the highlighted text in the
main window, or if nothing is selected, the line holding the text cursor.
Abort is the opposite to Execute. If a command is running, Abort will stop execution.
Create Movie… starts the process for exporting a Quicktime movie, first of all prompting you
for somewhere to save it, then asking for the movie attributes such as compression. See the
chapter Making Movies.
Finish Movie is used at the end of the movie-creating process, after capturing all the frames for
the movie. It finalises the movie and closes the file. If you hold down the option (alt) key while
displaying this menu, you get Finish Movie and Open, which opens the movie in your default
application for opening Quicktime movies (usually Quicktime).
The Full Screen menu entry can be used to put the Graphics Window into full screen mode,
i.e., you will not see the menu bar or any other windows. The Graphics Window needs to be at the
front, and you will probably want to set the Canvas Size to the size of the screen. In general, this is
not much use, because you cannot get to the Main Window to type in commands, but it can be
used as a sort of ʻkiosk modeʼ where a procedure is running for a long time, or the program is being
controlled remotely via Applescript (see Appendix E).
The next block of entries are to do with hiding and showing windows. They are all Hide or
Show followed by a window name:
Graphics the window containing the turtle; where all drawing takes
place
Procedures the window used to create and edit procedures. See the
Procedures chapter.
Trace Used to trace the execution of commands and
procedures.
Info Information about the state of the Turtle, current colours,
etc:
72
The Help Menu
Tutorials
73
If you are running Leopard (OSX 10.5) or above, the first entry is the Spotlight search item. You
can type text directly in here to find an item in ACSLogo Help.
The next item, ACSLogo Help, takes you to the help for ACSLogo in the OSX Help Viewer
window.
In the next group of items, Website takes you to the ACSLogo website, www.alancsmith.co.uk/
logo. Email will open a new email in your email client (such as Mail) to send me feedback.
The next item, Look Up, is used to look up individual commands in the Help files. To use this,
select a command in the main window and then choose Look Up. You can also hold down the
command key and double-click on a command.
The next block of commands relate to individual sections in the Help files. This is quicker than
choosing ACSLogo Help and drilling down.
The final block of entries contains the tutorials. These are files held in the tutorials folder
which should be in the same folder as the ACSLogo application – so you can add to and remove
from the folder if you like and ACSLogo will pick up the changes on restart and change the display
of the menu accordingly.
74
Appendix B: Preferences
Choosing Preferences… from the ACSLogo menu, displays the Preferences window:
The preferences window has three tabs. The first one that opens is the Turtle tab.
75
Smooth Lines causes lines drawn by the turtle to be anti-aliased, or smoothed, reducing the
jagged appearance. This is the technique used by OSX to make fonts appear smooth. You can see
the difference with these lines:
Anti-aliased (smoothed)
The Wrap checkbox determines what the turtle does when it gets to the edge of the canvas. By
default, it just goes of the edge, and you can't see it anymore. If you turn on Wrap, the turtle comes
in the other side. Let's look at an example of a window which is 400 pixels wide by 400 pixels high.
The left-hand examples have Wrap off, the right-hand examples have it on.
Starting position
(0,0)
Bottom of canvas
(0,-200)
This is the starting position after a Clearscreen command with the turtle at position (0,0) - the x
co-ordinate is zero, and the y co-ordinate is zero.
Now issue Forward 150. This increases the y co-ordinate by 150.
76
Wrap Off Wrap On
New position
(0,150)
Then issue Forward 150 again. This increases the y co-ordinate from 150 to 300.
Wrapped position
(0,-100)
The unwrapped Turtle has gone past the top of the canvas at y=200, so is no longer visible.
The wrapped Turtle, hitting the top of the canvas after travelling 50 pixels, comes in the bottom
of the canvas. It still has 100 pixels to go (it was told to go forward 150 pixels), so draws a line from
y=-200 to y=-100.
When drawing a line which is much longer than the canvas dimensions, the wrapping may
occur several times. For instance, given the commands:
Right 5
Forward 1050
77
You get this result:
The Turtle Speed slider allows you to change the speed of the Turtle. In previous versions of
the program, as the Turtle moved forward, drawing a line, the line would be drawn (taking
milliseconds), and the Turtle would just be drawn at the end of the line. So, when drawing a
rectangle, you would just see the Turtle drawn momentarily at each corner. This is not very good
for teaching purposes, as you get no impression of the Turtle ʻtravellingʼ along itʼs route. The slider
changes this - when the slider is at its maximum (its rightmost setting), the turtle moves as quickly
as in previous versions. When you drag the slider to the left, the Turtle moves more slowly, and you
can see it travel from position to position, and rotate slowly as well.
Near the bottom of the Preferences window is an array of Turtle images. Select any of these to
use it as the Turtle image. You can even add your own turtle image by dragging an image into the
array. The image needs to have a transparent area around the turtle – otherwise a white rectangle
gets drawn around the turtle. This means you probably need to use a TIFF or a PNG image. For
more details, see Appendix C: Roll your own Turtle.
At bottom right is the Defaults button - hit this to reset the Turtle preferences to their defaults.
Under the ʻMain Windowʼ heading is a Pop-up menu entitled Secondary Execute Key. Under
the default set-up, you need to hold down the command key when you press return in order to
execute a command. This Pop-up menu allows you to specify an additional key to execute a
command: you can specify return or a function key. Normally, pressing return on its own just inserts
78
a line in the text. if Return is selected from the Pop-up menu, pressing the return key will execute
the command. This makes it similar to traditional command-line versions of Logo. To insert a
newline in the text, hold down the control key while pressing enter. You can also specify a function
key as the secondary command key. This will work as long as the function key is not assigned to a
system function (such as Exposé).
Under the Procedures Window heading are a number of controls which affect editing in the
Procedures window. All text in the procedures window has the same font. This can be set using the
Font and Font Size pulldowns.
Checking the Syntax Coloration checkbox causes brackets and operators to appear in
different colours from the main text.
When the Auto-indent checkbox is checked, if you indent a line by a number of spaces and
press enter to insert a newline, the next line is indented by the same amount.
79
Appendix C: Roll Your
Own Turtle
The Turtle pane of the Preferences window allows you to define your own turtle. The array of
turtles at the bottom allows you to drag in an image of your choice.
The turtle image should be square, and the ʻTurtleʼ should be facing upwards. The area
around the Turtle should be transparent rather than white so that it does not draw a white square
over the background. For this reason, the image should be in a format which supports
transparency such as PNG or TIFF. This can be prepared in Photoshop using layers, but if you
donʼt have Photoshop, hereʼs a way using a drawing done in ACSLogo itself.
Rather than creating a drawing of my own, Iʼll use a symbol from a symbol font.
Set your canvas size to about 400 x 400 pixels, then try these commands:
ClearScreen
SetFont [ZapfDingbatsITC]
SetTypeSize 200
GraphicsType [/]
80
To use the symbol as a turtle, I need to centre it in the canvas and make it point upwards. Itʼs
pointing to the right at 90 degrees, so if I turn the Turtle to the left before drawing the symbol, it
should have the correct orientation:
ClearScreen
SetFont [ZapfDingbatsITC]
SetTypeSize 200
Left 90
GraphicsType [/]
Itʼs pointing the right way now, but itʼs not centred
– itʼs offset up and to the left – so if I offset the Turtle
down and to the right before drawing, it should be in
the right position. I can estimate the amount to offset
by using the Info window, and positioning the mouse
pointer at the centre of the symbol.
Mouse centred
over symbol
Mouse Pointer
co-ordinates
81
ClearScreen
SetFont [ZapfDingbatsITC]
SetTypeSize 200
PenUp
SetPosition [69 -96]
PenDown
Left 90
GraphicsType [/]
I can then export the image as a TIFF image file from the File/Export/Graphics… menu item.
If I then drag the image into the Turtle array in the Preferences Window, I get this (Iʼve dragged
the size slider upwards to make the image bigger:
The white background from the canvas has been drawn as well, drawing over the background.
This is not what we want — that area should be transparent so that only the symbol itself is drawn.
Back to the drawing board, er, canvas.
So we need to draw a transparent background. This is done by setting the opacity for colour
zero (the background colour) to zero. The ClearScreen command will then set the background to
completely transparent:
82
SetRGB 0 [0 0 0 0]
ClearScreen
SetFont [ZapfDingbatsITC]
SetTypeSize 200
PenUp
SetPosition [69 -96]
PenDown
Left 90
GraphicsType [/]
It looks like the background has been filled with black, but actually itʼs been filled with nothing.
Drawing the symbol in black on this background means we canʼt see it, but itʼs still there.
83
Appendix D: Localisation
Localisation is the customisation of a programʼs interface to make it usable in languages other
than English.
ACSLogo, in common with most other Mac OS X applications, has always allowed a certain
amount of localisation by the knowledgeable user — menus and dialogs may have their constant
fields translated into a non-English language by editing the resources in the ACSLogo application
bundle.
Version 1.4b added to this by allowing translated commands to be used instead of the English
ones. For example, in a German translation, Vorwart might be used instead of Forward.
This means that ACSLogo can be localised for a new language without any program coding
changes.
There are three parts to localisation:
The GUI Localising the static text in menus, dialogs, etc. Also localising
dynamic text such as Hide/Show menus and Undo strings.
Logo Commands Translating the Logo commands into your chosen language.
Help and Tutorials Localising the help files and tutorials included in the help menu.
There's no compulsion to do all of these — you could for instance just do the GUI.
Prerequisites
You need to have the free OS X Developer Tools installed. These come on a separate disk
with the operating system, often called 'XCode Tools', but it varies with operating system release.
84
The Application Bundle
In the Finder, a program looks like a single file. In fact it is a ʻbundleʼ — a directory of files and
sub-directories including the runnable code and a number of resources. To see the structure, right-
click (control-click) on the ACSLogo icon and choose ʻShow Package contentsʼ:
In the resulting window, choose column view if youʼre not already in it. Everything weʼre
interested in is in the Resources folder. Here you can see some tiffs which are used for turtle
images and other images used in the program. Weʼre interested in the languages folders —
English.lproj, German.lproj, etc. English.lproj is the ʻoriginalʼ folder that holds all the English
language resources. You can see that some localisation has been done for French, German,
Italian, and Spanish. To add another language, you would create an additional folder for that
language.
Look in the English.lproj folder:
85
You can see the .nib files, which are the interface files representing menus, windows, etc. The
Logo commands folder contains the help files. defaultcommandmap.plist is used for mapping
commands.
There are fewer .nib files, because some windows did not need translating. There is no Logo
Commands folder, so Help has not been translated. commandmap.plist overrides
defaultcommandmap.plist in English.lproj. Localizable.strings is a list of English strings used in the
program and their French equivalents.
Localisation Tasks
You first need to create a .lproj folder for your chosen language. For example, to localise in
Dutch, you would create a folder called Dutch.lproj (if you look in the Resources folder for OS X
programs such as Textedit or iCal, you will see the sorts of names you can use). All the localisation
will be done in this folder.
The three localisation tasks are described in the following sections:
GUI Localisation
Logo Command Localisation
Help and Tutorial Localisation
GUI Localisation
The .nib File
We'll start with the ACSLogo menus. Copy MainMenu.nib from English.lproj into your
new .lproj folder. Double-click on the file to open it up. As long as youʼve installed the developer
tools correctly, thisʼll start up the Interface Builder program. The following discussion describes
Interface Builder in the Leopard release of Mac OSX. This is quite different from the Tiger version,
although the principles are the same. See the Interface Builder documentation for detailed
instructions on how to use the program.
86
When you double-click on the .nib file, Interface Builder starts up and opens a number of
windows. This is the main one:
It shows the objects in the nib file. Double-click the MainMenu instance — this will open the
MainMenu object (if itʼs not already open) and allow you to edit it. Click on each menu to show the
menu items under it.
To change the text, just double-click on it, and type in your translation:
87
to open it up.
In the same way as for the menus, you can double-click on the strings to edit them. You will
probably find that the size of the string has changed after translation, so you may need to resize the
string or move it to keep it aligned with other objects. If you select the string by clicking on it, you
can drag it or pull the handles to resize it.
To change the title of the window, select Tools/Attributes Inspector and key in the new title:
Save the nib file. You can now try out the program, and you should see that the menu and
window strings have changed.
If you have a look in the Window menu, you'll see that some of the menu items that you
translated are still in English:
88
This is because these items arenʼt picked up from the nib, theyʼre set dynamically — the menu
items have to change as windows are shown or hidden. There are a number of dynamic menu
titles and other strings throughout the program. This problem is addressed using a file called
Localizable.strings.
Localizable.strings
You can find the Localizable.strings file in any of the .lproj folders which have had some
localization done. Itʼs just a unicode text file, and you can open it in XCode. This is an excerpt from
the French one:
It consists of a number of lines of the form English string = translated string. So for instance, the
translation for Show Info is Afficher Info. To create your own translation, copy this file into your .lproj
folder and translate each string in the file. Back up the file before changing it — Iʼve had corruptions
when editing these files within XCode in the past.
Once you've saved the file, that's the interface translation finished. You can leave it there, or
you can carry on localising with Logo Command Localisation.
89
Checking the switch will turn on localised commands if they exist (of course, the preferences
panel will appear in the current language).
You can see the full list of commands that need to be translated and their equivalents in
French and German in the command table. Localising the commands involves creating a list of
commands translated from the English ones. This creates a command mapping:
AVANCE FORWARD
AV
CAP HEADING
CHAR CHAR
So the French command Avance and its short version AV need to translate to Forward, Cap
translates to Heading, etc. In fact, this kind of mapping even occurs for English — a command like
SetPenColour may have several variants, such as a short form (SetPC) and an alternative spelling
(SetPenColor). These three forms map to the core ACSLogo command, SetPenColour. You can
see this mapping in the defaultcommandmap.plist file which is in the English.lproj folder. Double-
click it to open it – it should open in the Property List Editor.
The Root of the file is a dictionary – a list of keys and values. the keys are the commands
which the user is allowed to type in ACSLogo; the values are the core ACSLogo commands. So the
keys can be anything — you could add a key (and hence a command) called Piffle — but its value
would have to be from the finite set of core ACSLogo commands. You can see from the start of the
dictionary that it is mostly commands mapping to an identical value — ABS to ABS, AND to AND,
etc., but down a few entries you can see that both ARCCOS and ARCCOSINE map to ARCCOS –
so the user can use both.
Further down the list, you can see that SETPENCOLOUR, SETPC, and SETPENCOLOR map
to SETPENCOLOUR.
In general, you will not be changing this list for localisation, because it relates to mapping
English commands. You need to change a file called commandmap.plist found in the
localised .lproj folders. Got the French.lproj and open the one found there.
You can see that itʼs exactly the same format as defaultcommandmap.plist, the difference
90
being that the keys are French commands. The English commands on the right are the same core
commands as in defaultcommandmap.plist.
To create your own commandmap.plist file, copy defaultcommandmap.plist into your .lproj
folder and rename it. Edit the file and overtype the keys with the translations into your own
language. You can add entries, but the Value on the right must be one of the core ACSLogo
commands from defaultcommandmap.plist. You can remove entries, but if nothing maps to one of
the core commands, it will be inaccessible to the user. Once youʼve saved the file, turned on
localisation in the ACSLogo preferences, and restarted ACSLogo, your new commands are ready
for use.
When you restart the program, check in the Console utility (found in Applications/Utilities) to
see if there are any error messages.
The first two messages show that the values used in the command map are not core
commands, so the mapping for just those commands has failed. The last two messages show that
the two core commands have not been mapped to at all, so entries should be added.
91
Command Table
This is the list of English Commands with French and German equivalents.
92
FORWARD, FD AVANCE, AV VORWÄRTS, VW
FPRINT ECRITFICHIER, ECRITF DDRUCKE
FREADCHAR LITCARF, LITCARACTEREFICHIER DLIESBUCHSTABE
FREADCHARS LITCARACTERESFICHIER, LITCARSF DLIESBUCHSTABEN
FREADLIST LITLISTEF, LITLISTEFICHIER DLIESLISTE
FREADWORD LITMOTFICHIER, LITMOTF DLIESWORT
FSHOW AFFICHEF DZEIGE
FTYPE TAPEFICHIER, TAPEF DSCHREIBE
ERKENNEMAUSVERÄNDERUNG,
GETMOUSECHANGE SOURISCHANGE
EMAUSV
GETMOUSECLICK SOURISCLIC ERKENNEMAUSKLICK, EMAUSK
GETMOUSEMOVED SOURISBOUGE ERKENNEMAUSBEWEGUNG, EMAUSB
GETPROP, GPROP RPROP NIMMEG, NIMMEIGENSCHAFT
GO VA GEHEZU
TYPEGR, TYPEGRAPHIQUE,
GRAPHICSTYPE, GRTYPE GRAFIKTYP
ECRISGRAPHIQUE, ECRISGR
HEADING CAP KURS, WINKEL
HIDETURTLE, HT CACHETORTUE, CT VERSTECKIGEL, VI
HOME ORIGINE MITTE
IF SI WENN
INSTRUMENTS INSTRUMENTS INSTRUMENTE
INTEGER, INT ENTIER, ENT GANZZAHL
ITEM ELEMENT, ITEM ELEMENT, ELT
LABEL LABEL, ETIQUETTE IGELTEXT, IT
LAST DERNIER LETZTES, LZ, LE
LASTPUT, LPUT METSD, MD, METSDERNIER ML, MITLETZTEM
LEFT, LT GAUCHE, GA, TG, TOURNEGAUCHE LINKS, LI
LIST LISTE LISTE
LIST?, LISTP LISTE?, LISTEP LISTE?
LOCAL LOCALE LOKAL
LOG, LN LOG, LN LOG, LN
LOG10 LOG10 LOG10
LOWERCASE MINUSC, MINUSCULE KLEINBUCHSTABEN
MAKE RELIE SETZE
MEMBER?, MEMBERP MEMBRE?, MEMBREP MITGLIED?
MOUSE SOURIS MAUS
NAME?, NAMEP NOM? NAME?
NOT NON NICHT
NUMBERP, NUMBER? NOMBREP, NOMBRE? ZAHL?
OPENAPPEND OUVREAJOUT ÖFFNEZUMANHÄNGEN
OPENREAD OUVRELECTURE ÖFFNEZUMLESEN
OPENTEXTAPPEND OUVRETEXTEAJOUT ÖFFNETEXTANHÄNGEN
OPENTEXTREAD OUVRETEXTELECTURE ÖFFNETEXTLESEN
OPENTEXTWRITE OUVRETEXTEECRITURE ÖFFNETEXTSCHREIBEN
OPENWRITE OUVREECRITURE ÖFFNEZUMSCHREIBEN
OR OU EINES
OUTPUT, OP RET, SORTIE, RETOURNE, SOR RÜCKGABE
PATHBOUNDS LIMITESTRACE PFADGRENZE
PATHLENGTH LONGUEURCHEMIN PFADLÄNGE
PEN CRAYON, PLUME STIFT
CPLUME, COULEURCRAYON,
PENCOLOUR, PENCOLOR, PC FARBEZ
CCRAYON, CC, COULEURPLUME
PENDOWN, PD BC, BAISSEPLUME, BAISSECRAYON SA, STIFTAB
PENUP, PU LEVECRAYON, LC SH, STIFTHOCH
PENWIDTH TAILLECRAYON, TAILLEPLUME STIFTBREITE
PI PI PI
PLAY JOUERINSTRUMENT, JOUER SPIELE
POSITION, POS POSITION, POS IGELORT, ORT
POWER PUISSANCE POTENZ
PRINT EC, ECRIS DRUCKEZEILE, DR, DZ, DRUCKE
PRODUCT PRODUIT PRODUKT
PROPLIST, PLIST LPROP EIGENSCHAFTENLISTE
MITEG, GIBEG, MITEIGENSCHAFT,
PUTPROP, PPROP RAPE
GIBEIGENSCHAFT
PWD REPERTOIRE, REP ORDNER
QUOTIENT QUOTIENT QUOTIENT
93
RANDOM HASARD ZUFALL, ZZ
READCHAR, RC LITCAR, LITCARACTERE LIESBUCHSTABE, LBU
READCHARS, RCS LITCARACTERES, LITCARS LBUN, LIESBUCHSTABEN
READLIST, RL LITLISTE LIESLISTE, LL
READWORD, RW LITMOT LW, LIESWORT
REMAINDER RESTE REST
REMPROP EFPROP MERKEEIGENSCHAFT, MERKEG
REPEAT REPETE WH, WIEDERHOLE
REVERSEPATH INVERSETRACE PFADUMKEHREN
RGB RVB RGB
RIGHT, RT DR, DROITE RECHTS, RE
ROUND ARRONDI RUNDE
RUN EXEC, EXECUTE TUE
SAY PRONONCE SAGE
SENTENCE, SE PHRASE, PH SATZ
SETBACKGROUND, SETBG FIXECOULEURFOND, FCF AUFHINTERGRUND
LEINWANDGRÖSZESETZEN,
SETCANVASSIZE CHANGETAILLECANEVAS
LGSETZEN
SETCLIPPATH SETZEAUSSCHNITTPFAD
SETFONTFACE, SETFONT FIXEASPECTPOLICE, FIXEPOLICE AUFSCHRIFTART, AUFSCHRIFT
SETFONTFAMILY FIXEFAMILLEPOLICE AUFSCHRIFTFAMILIE
SETFONTTRAITS FIXESTYLE AUFSCHRIFTEIGENSCHAFTEN
SETFULLSCREEN VOLLBILDANZEIGE
SETHEADING FC, FIXECAP AUFKURS, AK
SETLINECAP DEFINITBOUTLIGNE LINIENENDESETZEN, LESETZEN
SETLINEDASH POINTILLES AUFSTRICHLINIE
SETPEN FIXECRAYON, FIXEPLUME AUFSTIFT
SETPENCOLOUR, SETPENCOLOR,
FCC, FIXECOULEURCRAYON FARBE
SETPC
FTP, FIXETAILLEPLUME,
SETPENWIDTH AUFSTIFTBREITE
FIXETAILLECRAYON, FTC
FIXEPOS, FIXEPOSITION, FPOS,
SETPOSITION, SETPOS AUF, AUFXY
FPOSITION
SETRGB FIXERVB AUGRGB
SETSHADOW FIXEOMBRE AUFSCHATTEN
SETTYPESIZE FIXETAILLE AUFSCHRIFTGRÖßE
SETVOICE FIXEVOICE AUFSTIMME
SETWRAP
SETX FIXEX AUFX
SETY FIXEY AUFY
SHOW MONTRE, AFFICHE ZEIGE, DZL, GIB
SHOWN?, SHOWNP ESTAFFICHE?, VISIBLE SICHTBAR?
SHOWTURTLE, ST MT, MONTRETORTUE ZGI, ZI, ZEIGIGEL
SINE, SIN SINUS, SIN SINUS
SINH SINH SINH
SNAP CAPTUREIMAGE, CAPTURE KNIPSE
SQRT RACINE QUADRATWURZEL, QW, WURZEL
STOP ARRETE HALT, STOPP
STROKECURRENTPATH DESSINETRACECOURANT AKTUELLERPFADUMRISS
STROKEPATH DESSINETRACE PFADUMRISS
SUM SOMME SUMME
TANGENT, TAN TAN, TANGENTE TAN, TANGENS
TANH TANH TANH
TEXT TEXTE TEXT
TEXTBOX ZONETEXTE TEXTBOX
THING CHOSE WERT
THROW RENVOIE WIRFZURÜCK
TIME HEURE ZEIT
TOWARDS VERS RICHTUNG, RI
TYPE TYPE SCHREIBE
UPPERCASE MAJUSCULE GROßBUCHSTABEN
VOICE VOIX STIMME
VOICES LISTEVOIX STIMMEN
WAIT ATTENDS WARTE
WAITFORSPEECH ATTENDSPAROLE WARTEAUFSPRACHE
WORD MOT WORT
94
WORD?, WORDP MOTP, MOT? WORT?
WRAP UMBRUCH
XPOS POSX, XPOS XORT
YPOS YPOS, POSY YORT
95
Help and Tutorial Localisation
There are a number of different bits of documentation that come with ACSLogo (including this
user guide). Two of them are integrated with the program — Tutorials and Help. To localise them,
you have to have some knowledge of how they fit into the program.
Tutorials
When you start up ACSLogo, you can see the tutorials at the bottom of the Help menu:
The tutorials are just files created in ACSLogo and saved in the tutorials folder. Their names
have been prefixed with numbers to make them appear in a particular order. You can add, replace,
rename, or change the files. The program will pick up the changes on restart.
Help
ACSLogo provides help using the standard Apple Help system. The help is contained in a set
of indexed HTML files. A few pages back we looked in the application bundle and saw in the
English.lproj folder a folder called Logo Commands.
The folder contains a folder called html which contains the bulk of the help HTML and image
files; Logo Commands idx which is an index into the HTML files used by the Apple help system; a
couple of other HTML files which are needed by the Help system for navigation.
96
If you look at one of the files in the html folder, you will see that it is valid html, with a number of
added tags:
There is one of these blocks for each command. The AppleSegStart, AppleSegDescription,
and AppleSegEnd tags, and the bits they enclose, are required by the Apple Help System for
indexing.
Once youʼve created your HTML, you need you need to run the folder through the Help
Indexer found in /Developer/Applications/Utilities. You need to give it the folder, which is the html
folder.
97
Appendix E: Applescript
Version 1.4g of ACSLogo introduces the ability to execute commands from another process via
Applescript.
Applescript in General
Applescript is a scripting language which enables you to control Applescript-enabled
applications such as iTunes and the Finder. An Applescript-enabled application declares an
interface of commands which can be called from a script.
To create, test, and run a script, use AppleScript Editor located in Applications/Utilities.
An empty window opens for you to type in your script. Here I've typed a script which asks the
Finder for the name of its front window.
Clicking the Run button compiles the script and runs it, returning any result in the bottom pane.
Note that I could also write this script as:
tell application "Finder"
tell front window
name
end tell
end tell
or as
98
To execute this from Applescript:
tell application "ACSLogo"
tell document 1
execute command "Repeat 4 [Forward 100 Right 90]"
end tell
end tell
Note that the command has to go to a document within the application. Document 1 is the first
document in the list of documents held by the application.
The script returns straight away — it does not wait for the command to execute. Also, if the
command has a return value, this is not returned to the script, but is printed out in the Logo main
window in the usual way.
Running Scripts
Local Applescript
As you've seen, you can go into AppleScript Editor to run the script. You can also make the
script into an application so that you can double-click on it to run it — just do a Save As… and
choose a file type of Application.
Terminal
Another approach is to run the script from the command line using Terminal. This is done by
going into Terminal and invoking a program called osascript:
osascript scriptlogo.scpt
on run argv
tell application "ACSLogo"
tell document 1
execute command argv
end tell
end tell
end run
99
Remote Applescript
You can run an Applescript on one machine to control a program on another machine.
On the machine which is being controlled (the remote machine), you need to check the
Remote Apple Events checkbox in the Sharing pane of System Preferences.
On the machine where you're doing the typing (the local machine), you need to set up the
applescript like this:
The variable remoteMac contains the required userid and password on the remote machine
and its address. You can use the IP address, as I've done here, or the name the machine is known
by on the network.
ACSLogo must also be installed on the local machine. This is so that Applescript can access
ACSLogoʼs Applescript dictionary locally in the using terms line.
In this example, ACSLogo is just being told to quit.
100