penSpace is an introductory subset (or ‘space’) of turtleSpaces’ complete functionality. It is the first of eight spaces, each of which introduces more features.

penSpace introduces basic turtle movements and pen-related primitives (keywords). Loops are possible using repeat, and there are some primitives for randomly setting turtle parameters like position and pencolor. There are about 50 primitives available in the penSpace environment.

Console (Interactive Text Area)


help

help “primitive

Displays the help entry for the given ‘primitive’ (a keyword used in turtleSpaces such as a forward). The primitive name must be quoted.

help "forward
to

to procedure

Prompts for the creation of a new procedure. The procedure name may or may not begin with a quote ”

to procedure
to "procedure
save

save

Saves the project.

save
savepng

savepng [width height] “name

Saves a screenshot to the local computer of the given width and height with the given name.

save [1024 960] "mypicture
addto

addto “procedure

Allows for the adding of additional code to the given procedure from the console. Note that the procedure name must begin with a quote.

addto "procedure
assemble

assemble “procedure

Creates a procedure based on the current ‘turtle track’, the lines and shapers created on-screen.

assemble "procedure
print

print value
print “word
print |phrase with spaces|
print [list. ofi tems]
pr “word etc.

Prints the provided value to the screen. This can be a number, word, phrase, list or a ‘returner’ such as pencolor.

print 10 + 2
print pencolor
print |I am a duck.|
fullscreen

fullscreen
fs

Hides the console text area in fullscreen mode (entered by clicking the green triangle in the top-right corner of the browser window)

fullscreen
splitscreen

splitscreen
ss

Returns to displaying the console text at the bottom of the screen when in fullscreen mode.

splitscreen

Canvas (Environment)


hideturtle

hideturtle
ht

Hides the display of the turtle on the canvas.

hideturtle
showturtle

showturtle
st

Shows the turtle on the canvas.

showturtle
reset

reset

Resets the environment: clears the canvas and restores all settings to defaults.

reset
clearscreen

clearscreen
cs

Clears the canvas and moves the turtle to the home position. Color and other settings are left intact.

clearscreen
clean

clean

‘Cleans’ the canvas, leaving the turtle where it is.

clean
showcolors

showcolors
sc

Shows the colors and their numeric values. However, there are also predefined functions with the name of each color that return the appropriate numerical value and may be used in place of their numbers. These functions are:

red blue green black magenta green gray mediumblue lightblue brown orange lightgray pink lightgreen yellow cyan white

showcolors
home

home

Returns the turtle to its home position at the center of the canvas.

home
leftedge rightedge bottomedge topedge

leftedge
rightedge
bottomedge
topedge

Returns the values of the associated canvas edges.

print leftedge
sety bottomedge

Turtle Movement (Basic)


home

home

Returns the turtle to its home position at the center of the canvas.

home
forward

forward steps
fd steps

Moves the turtle forward the given number of steps. Draws a line if the pen is down. See pendown

forward 20
back

back steps
bk steps

Moves the turtle backwards the given number of steps. Draws a line if the pen is down.

back 30
slideleft

slideleft steps
sl steps

Slides the turtle to the left the given number of steps. Draws a line if the pen is down.

slideleft 30
slideright

slideright steps
sr steps

Slides the turtle to the right the given number of steps. Draws a line if the pen is down.

slideright 30
left

left degrees
lt degrees

Turns the turtle to the left the given number of degrees (360 degrees is a full rotation).

left 30
right

right degrees
rt degrees

Turns the turtle to the right the given number of degrees (360 degrees is a full rotation).

right 30
leftarc

leftarc degrees radius
larc degrees radius

Moves the turtle forward in an arc to the left of the given number of degrees and the given radius. Draws a line if the pen is down.

leftarc 90 50
rightarc

rightarc degrees radius
rarc degrees radius

Moves the turtle forward in an arc to the right of the given number of degrees and the given radius.Draws a line if the pen is down.

rightarc 30
setxy setx sety

setxy xpos ypos
setx xpos
sety ypos

Moves the turtle to the given x (xpos), y (ypos) or x and y co-ordinates. The center of the view window is 0 0. To the left of this point, xpos becomes negative. To the right, it is positive. Similarly, ypos becomes negative below center, and positive above it.

setxy -30 60
setx 50
sety -20
xpos ypos

xpos
ypos

Returns the current x.co-ordinate of the turtle, or the y co-ordinate, respectively.

print xpos
print ypos
randomposition

randomposition
randpos

Moves the turtle to a random position on the canvas.

randomposition
setheading

setheading heading
seth heading

Sets the turtle’s heading in degrees, between 0 and 360.

setheading 180
heading

heading

Returns the turtle’s heading in degrees, between 0 and 360.

print heading
randomheading

randomheading
randhead

Rotates the turtle to a random heading.

randomheading
backtrack

backtrack
bt

Undoes the last turtle command.

backtrack
pushturtle

pushturtle
pusht

‘Pushes’ the turtle’s state (position, orientation, pencolor etc.) to a ‘stack’ from which it can be retrieved later.

pushturtle
popturtle

popturtle
popt

‘Pops’, or restores a saved state from the pushturtle ‘stack’. The last state ‘pushed’ is the first state ‘popped’.

popturtle

Turtle Pen


penup pendown

penup pendown
pu pd

Raises and lowers the turtle’s pen. When the pen is raised, it does not draw.

penup
pendown
setpencolor

setpencolor numberp
setpc number

Sets the color to be drawn using the turtle’s pen. This is a number between 0 and 15, the colors represented by each numerical value can be viewed using the showcolors command. However, there are also predefined functions with the name of each color that return the appropriate numerical value and may be used in place of their numbers. These functions are:

red blue green black magenta green gray mediumblue lightblue brown orange lightgray pink lightgreen yellow cyan white

setpencolor 3
setpencolor red
pencolor

pencolor
pc

Returns the current pencolor.

setpencolor pencolor + 1
randompencolor

randompencolor
randpc

Sets a random pencolor which is not the current pencolor nor the current fillcolor.

randompencolor
setpenshade

setpenshade shade
setps shade

Sets the ‘shade’ of the color drawn by the turtle’s pen. This is a value from -15 to 15, where negative numbers are lighter and positive numbers are darker.

setpenshade 5
penshade

penshade
psh

Returns the current pen shade value.

print penshade
randompenshade

randompenshade
randps

Sets a random penshade which is not the current penshade.

randompenshade
setpenopacity

setpenopacity opacity
setpo opacity

Sets the opacity of the color drawn by the turtle’s pen. This is a value from 0 to 100, where 0 is entirely transparent, and 100 is fully opaque.

setpenopacity 50
penopacity

penopacity

Returns the current pen opacity value.

print penopacity
setpenwidth

setpenwidth width
setpw width

Sets the width of the line drawn by the turtle’s pen. This is a value from 1 to 100.

setpenwidth 5
penwidth

penwidth
pw

Returns the current pen width.

print penwidth
pencaps

pencaps

Enables pencaps, which put little ‘caps’ on the start and end of lines.

pencaps
nopencaps

nopencaps

Diisables pencaps.

nopencaps
penjoins

penjoins

Enables penjoins, which places intermediate segments between two differently-angled lines.

penjoins
nopenjoins

nopenjoins

Diisables penjoins.

nopenjoins

line

line steps

Creates a line of the given length in front of the turtle.

line 20

Numbers


+ – / *

3 + 2
10 – 5
4 / 2
3 * 4

Basic math operators. Uses BEDMAS evaluation. Round brackets may be used to control order of operations ().

print 3 + 5 * 2
print (3 + 5) * 2
pick

pick [list of numbers]

Randomly returns one of the values in the provided list.

print pick [1 2 3 4 5]
print pick range [20 50]
item

item index [list of numbers]

Returns the item in the provided list at the given index.

print item 3 [1 2 3 4 5]

Loops


repeat

repeat loops [list-of-instructions]

Repeats the given list of instructions the specified number of loops. The repcount function returns the current iteration.

repeat 50 [fd 50 rt 18]
repcount

repcount

Returns the current iteration of the executing repeat loop.

repeat 50 [print repcount]
repeat 50 [forward repcount right 10]
repabove

repabove level

Returns the current iteration of the repeat loop at the specified level ‘above’ the current repeat loop.

repeat 10 [repeat 10 [print repcount * repabove 1]]
reptotal

reptotal

Returns the total number of iterations of the executing repeat loop.

repeat 5 [print reptotal - repcount]
loopcount

loopcount

Returns the current iteration of the executing forever loop.

forever [print loopcount]

Execution 


stop

stop

Stops program execution.

stop