Pen and Color Commands
Command |
Shorthand |
Description |
PenUp () ; |
PU |
Move the turtle's pen up (no
longer draws) |
PenDown () ; |
PD |
Put the turtle's pen down (will
draw or erase as set) |
SetPenSize ( Number ) ; |
Set the width of the line the
turtle's pen will draw |
|
SetPenColor ( List ) ; |
Takes a list consisting of three
numbers and sets the red, blue and green values for the color of the pen to
those values (numbers should be between 0 and 255) |
Moving and Turning Commands
Command |
Shorthand |
Description |
Forward ( Number) ; |
FD |
Move the turtle in the current
direction the number of pixels |
Backward ( Number) ; |
BK |
Move the turtle in the opposite
direction it is facing the indicated number of pixels |
LeftTurn ( Number) ; |
LT |
Turn the turtle left the indicated
number of degrees |
RightTurn ( Number) ; |
RT |
Turn the turtle right the
indicated number of degrees |
Turtle and Position Commands
Command |
Shorthand |
Description |
ShowTurtle () ; |
|
Make sure the turtle appears on
the screen |
HideTurtle () ; |
Remove the turtle from the screen
(it is still there, just hidden) |
|
Position () ; |
Returns a list of two elements
with the X and Y position of the turtle |
|
Heading () ; |
Returns a single value, the
current heading of the turtle in degrees |
|
SetPosition ( List ) ; |
|
Takes a list of two numbers and
sets the X,Y position of the turtle to those values |
SetHeading ( Number ) ; |
|
Set the heading of the turtle to
the value provided in degrees |
Logo
Data Structures and Variables
The base types of KLogo are numbers, strings, and boolean values. Number constants consist of an
optional sign (+ or -) followed by one or more digits, and an optional period
which can be followed by one or more digits followed by an optional e or E with
an optional sign followed by one ore more digits.
Examples of Number constants include 0, 12, 13.1, -14.23e-02, +1.41e10,
etc.
Strings are represented by an
opening double quote character (") followed by 0 or more characters and
finishing with a double quote. The characters \t and \n refer to the tab and
return characters. A " in the string is signified
by \" and a backslash is signaled by \.
Boolean constants include True
and False.
A list in KLogo
consists of a set of 0 elements between square brackets. Each element of a list
can itself be a number, a boolean
value, or a list. Examples of lists in KLogo would be
[] (the empty list), [1 2], [1 [3] 2], etc.
Variable names in KLLogo start with a letter and are followed by one or more
letters, digits, underscore or question mark (?) characters. Examples of names
include Hello, A_Var, Junk49, etc.
A variable in KLogo
is declared as
A variable may be set using the Make
command. The command has the format: Make VariableName
Value ;
Operators
KLogo includes a number of predefined operators that can be
applied to values of appropriate type.
In KLogo
if Expr1 and Expr2 are numbers, then so are:
In KLogo
if Expr1 and Expr2 are booleans, then
so are:
In KLogo
if Expr1 and Expr2 are values, then so are:
The following operators can be
applied to a value Expr and returns true if the value
is of the given type:
Some specific list and string
related operators include:
Other
Basic Control Commands
if Expr { CommandList
} - if Expr is true the list of commands is
executed
ifelse
Expr { IfCommandList
} { ElseCommandList } - if Expr
is true the list IfCommandList is executed,
otherwise ElseCommandList
for { VariableName
StartExpr StopExpr [ StepExpr ] } { CommandList
} - sets VariableName to the values starting
with StartExpr and ending with StopExpr steping the value
by an optional StepExpr each time (otherwise
the step is 1 or -1 as appropriate), each time through the loop the CommandList is executed with VariableName
set to that value
while Expr { CommandList
} - while Expr is true the list of commands is
executed and the expression then again tested
print ( Expr ) ; - prints out an
ascii representation of Expr
to the command window
wait ( Expr ) ; - if Expr is a number then it waits 1/60th of a second
for each whole value of Expr
read ( Type ) - is an operator that reads a value from
the command line and returns a value of the appropriate Type such as
Number, Boolean, String or List.
Creating
New Commands/Operators
To ReturnType
NewCommandName ( Type1 ParamName1 Type2
ParamName2 ...) { CommandList } - declares
a new command or operator, the ReturnType is
one of Void, Number, Boolean, String or List and the parameter list is a list
of 0 or more parameters each with a type (one of Number, Boolean, String or
List) and then a parameter name. The CommandList is a
series of commands to execute that may also include a return statement, in the
case of a Void command it would simply be return; in the other cases it would
be return Expr;
Comments
Comments are started by % and
anything following that on that line is ignored.
White
Space
White space includes space, tab and
return characters.
Written by Richard F Maclin.