artSpace is an subset (or ‘space’) of turtleSpaces’ complete functionality. It is the second of eight spaces, each of which introduces more features. Following on from penSpace, artSpace introduces filled shapes, gradients, orbits and a few other goodies :)

There are around 100 primitives in artSpace.

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
setbackgroundcolor

setbackgroundcolor color
setbg color

Sets the background color to the given color index. This is a number between 0 and 15, the colors represented by each numerical value can be viewed using the showcolors command.

setbackgroundcolor pink
setbackgroundcolor 5
backgroundcolor

backgroundcolor
bg

Returns the numeric value of the current background color.

print backgroundcolor
randombackgroundcolor

randombackgroundcolor
randbg

Sets a random background color that is not the current background color.

randombackgroundcolor
setbackgroundshade

setbackgroundshade shade
setbs shade

Sets the background shade to the given value. This is a number between -15 (white) and 15 (black).

setbackgroundshade 5
backgroundshade

backgroundshade
bgs

Returns the numeric value of the current background shade.

print backgroundshade
randombackgroundshade

randombackgroundshade
randbs

Sets a random background shade that is not the current background shade.

randombackgroundshade
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

wrap

wrap

Causes the turtle to ‘wrap’ from one side of the canvas to the other when it crosses an edge. This is the default behavior in artSpace.

wrap
fence

fence

Causes both the turtle and program execution to stop if the turtle attempts to cross the edge of the canvas. Use the try command to handle the error caused by fence.

fence
fence repeat 40 [try [forward 10] [right 145]]

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 Movement (Advanced)


orbitleft

orbitleft degrees
olt degrees

Causes the turtle to orbit to the left around the anchor point the given number of degrees.

orbitleft 90
orbitright

orbitright degrees
ort degrees

Causes the turtle to orbit to the right around the anchor point the given number of degrees.

orbitright 90
dropanchor

dropanchor

Sets the ‘anchor point’ used by orbitleft and orbitright to the current position.

dropanchor
showanchor

showanchor

Causes the anchor point to be displayed using a small red dot.

showanchor
hideanchor

hideanchor

Hides the anchor point.

hideanchor
pullin

pullin steps
pui steps

‘Pulls’ the turtle in towards the anchor point the given number of steps.

pullin 10
pullout

pullout steps
puo steps

‘Pulls’ the turtle out away from the anchor point the given number of steps.

pullout 10
tether

tether

Ordinarily as the turtle turns, the anchor point orbits with it, always staying in front of the turtle. tether causes the anchor point to stay fixed, tethered to its current position.

tether
notether

notether

Causes the turtle to return to the default anchor point behavior, where the anchor point orbits around the turtle as it turns, staying in front of it.

notether
setorbitdistance

setorbitdistance steps

Arbitrarily sets the distance of the turtle from the anchor point. Moves the turtle, not the anchor point.

setorbitdistance 20
orbitdistance

orbitdistance

Returns the current distance from the turtle to the anchor point.

print orbitdistance
wiggle

wiggle steps wiggles size
wiggle [degrees] wiggles size
wiggle [degrees radius] wiggles size

wiggle steps [wiggles1 wiggles2] [size1 size2]

Creates a ‘wiggle’, a wavy line or arc depending on the type of parameters provided. The first form provided above is a straight wiggle, the second an ‘orbit’ wiggle that uses the existing anchor point and the third an arc wiggle, which uses the provided radius.

Wiggles can have one or two wave frequencies. Adding a second wave frequency greatly expands the variety of shapes that can be created with the wiggle.

wiggle 100 10 2
wiggle [360] 30 2
wiggle [360] [20 5] [1 2]

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 number
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
gradient

gradient

Enables gradient mode, which causes the color of a line to progressively change from the pencolor at the start to the fillcolor at the end.

gradient
nogradient

nogradient

Disables gradient mode.

nogradient
swapcolors

swapcolors

Swaps the pen and fill colors. Useful with gradients.

gradient forward 20 swapcolors forward 20
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
snip

snip

Removes the last position from the turtle’s ‘track’, creating a line between the current position and the second-last position (if the pen is down).

forward 20 right 90 forward 20 snip

Turtle Shapes (Fill)


beginfill 

beginfill

Starts collecting points used to create arbitrary shapes. Points (turtle movements) must form a coherent line in the order they are placed, and the line can not cross. Create the shape with endfill

beginfill
endfill 

endfill

Stops collecting points used to create arbitrary shapes and attempts to ‘fill’ the outlined area with the current fill color. If it is unable to create a shape, it will cause an error. This can be mitigated by using the try command, as shown in the second example, below. The points collected since beginfill was called are erased after endfill is executed, whether it succeeds or not.

endfill
try [endfill][]
pin 

pin

Marks a point which can be used with pinfill to create an arbitrary shape. This technique differs from beginfill and endfill in that rather than every turtle movement creating a point in a potential fill outline, the user must create the points themselves using pin.

pin
pinfill 

pinfill

Attempts to create a filled shape using the points selected by the user using the pin command. Unlike endfill, pinfill will not generate an error if it fails. Clear the pins with clearpins

pinfill
clearpins 

clearpins

Clears the list of pins currently collected.

clearpins
setfillcolor

setfillcolor number
setfc number

Sets the color to ‘fill’ shapes created by the turtle. 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

setfillcolor 2
setfillcolor blue
fillcolor

fillcolor
fc

Returns the current fillcolor.

setfillcolor fillcolor + 3
randomfillcolor

randomfillcolor
randfc

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

randomfillcolor
setfillshade

setfillshade shade
setfs shade

Sets the ‘shade’ of the color used to fill shapes. This is a value from -15 to 15, where negative numbers are lighter and positive numbers are darker.

setfillshade 5
fillhade

fillshade
fsh

Returns the current fill shade value.

print fillshade
randomfillshade

randomfillshade
randfs

Sets a random fillshade which is not the current fillshade.

randomfillshade
setfillopacity

setfillopacity opacity
setfo opacity

Sets the opacity of the color used to fill shapes. This is a value from 0 to 100, where 0 is entirely transparent, and 100 is fully opaque.

setfillopacity 50
fillopacity

fillopacity

Returns the current fill opacity value.

print fillopacity

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
random

random number
random [number]
random [start end]
random [start end divisor]

Returns a random number based on the provided value or list of values. If a single number is provided, then random returns a random number from 0 to one less than the provided value.

So random 10 returns a value from 0 to 9. If the provided item is a single list item, eg random [10] then random returns a number between 1 and the provided number inclusive (1 to 10). I

f a list of two number is provided, random returns a value between the two values, inclusive. So random [3 6] would return a random number from 3 to 6, including possibvly 3 and 6.

Finally, if a list of three values is provided, random returns a value from the first to the second which is divisible by the third value. So random [1 10 2] will return 2, 4, 6, 8 or 10.

print random 10
print random [10]
print random [1 5]
print random [1 10 2]
range

range [start end (step)]

Returns a list of numbers based on the provided list containing the start of the range, the end of the range and an optional ‘step’ value.

print range [1 10]
print range [2 10 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]
forever

forever [list-of-instructions]

Repeats the given list of instructions forever. The loopcount function returns the current iteration.

forever [fd 50 rt 18]
loopcount

loopcount

Returns the current iteration of the executing forever loop.

forever [print loopcount]

Flow Control and Booleans


if

if boolean [list of instructions]

If the provided boolean is true, execute the list of instructions.

if :animal = "duck [print "quack]
if 4 > 3 [print |4 is greater than 3|]
ifelse

ifelse boolean [list of instructions][list of instructions]

If the provided boolean is true, execute the list of instructions, otherwise execute the second list of instructions.

ifelse :age > 16 [print |You are older than 16|][print |You are 16 or less|]
=

value = value

Returns true if the first value equals the second value. Values can be numbers, words, phrases or lists.

print 3 = 2
if :age = 16 [print |You are sixteen!|]
>

value > value

Returns true if the first value is greater than the second value. Values can be numbers, words, phrases or lists.

print 3 > 2
if :age > 16 [print |You are older than sixteen!|]
<

value < value

Returns true if the first value is less than the second value. Values can be numbers, words, phrases or lists.

print 3 < 2
if :age < 16 [print |You are younger than than sixteen!|]
!=

value !!= value
value <> value

Returns true if the first value does not equal the second value. Values can be numbers, words, phrases or lists.

print 3 != 2
if :age != 16 [print |You are not sixteen!|]
<= >=

value >= value
value <= value

Returns true if the first value is greater than or equal to (or less than or rqual to) the second value. Values can be numbers, words, phrases or lists.

print 3 >= 2
if :age <= 16 [print |You are sixteen or younger!|]
and

and boolean boolean

Returns true if the first boolean is true and the second boolean is true.

print and 3 > 2 6 < 9
if and :name = "Fred :age = 16 [print |You are sixteen, Fred!|]
or

or boolean boolean

Returns true if either the first boolean is true and the second boolean is true.

print or 3 > 2 6 < 9
if or :name = "Fred :name = "Bob [print |You are either Fred or Bob!|]
oddp

oddp number

Returns true if the provided number is odd.

print oddp
evenp

evenp number

Returns true if the provided number is even.

print evenp
randomp

randomp number

Returns true if 0 = random X where X is the provided number. Basically like the computer rolling an X-sided die and then returning true if the 0 side comes up.

if randomp 10 [setpencolor red]

randomboolean

randomboolean
randbool

Randomly returns true or false.

ifelse randbool [forward 10] [back 10]
pencapsp

pencapsp

Returns true if pencaps is set.

print pencapsp
pencapsp

penjoinsp

Returns true if penjoins is set.

print penjoins
wrappedp

wrappedp

Returns true if the turtle has ‘wrapped’ the canvas edge. Reading wrappedp causes it to reset to false.

print wrappedp

Execution 


stop

stop

Stops program execution.

stop
wait

wait 60ths of a second

Pauses program execution for the given 60ths of a second. wait 60 would pause for one second.

wait 60
run

run [list of instructions]

Executes the given list of instructions.

run [forward 20]
run pick [[forward 20][back 20]]
try

try [list of instructions][list of instructions]

Executes the first list of instructions and if there is an error executes the second list of instructions.

fence repeat 100 [try [fd 50] [rt 120]]
break

break

Breaks out of the current loop and returns to executing beyond it.

break
output

output value

Returns the given value to the calling procedure. Used to return data from one procedure back to another.

output 49