Skip to content
/ Turtle Public

Turtle Graphics using stack lang of single-character commands and quotations

Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



4 Commits

Repository files navigation

Turtle Graphics

A very simple Turtle Graphics implementation using HTML5 canvas and JavaScript. Usage instructions are available on the web page (Default.htm). For example, this draws a “galaxy”:


Give it a try:

There's also a YouTube demo here:

It is driven by a tiny stack language allowing single-character commands to move the turtle and draw and do animations. Quotations are used to treat code as data (pushed to the stack); allowing repetition and definition of new commands.

h Home - Reset x,y to 160,160

n North - Reset bearing

g Go - Sets x,y from stack 10,20g

c Clear - Clears canvas (useful for animation)

f Forward - Draws forward n pixels 10f

m Move - Moves forward n pixels 10m

l Left - Turn bearing left n degrees 90l

r Right - Turn bearing right n degrees 90r

x Repeat - Repeats quotation n times (100f90r)4x

a Add - Adds two numbers 4,2a

- Subtract - Subtracts two numbers 4,2-

* Multiply - Multiplies two numbers 4,2*

v Divide - Divides two numbers 4,2v

j Join - Prepends head onto quotation 10(f90r)c

u Unjoin - Separates head from tail (10f90r)u

d Dup - Duplicates top stack value

w Swap - Swaps top two stack values

o Drop - Discards top stack value

i Dip - Applies quote below next value 10,20(f)i

Parenthesis surround quotations (100f90r).

Digits [0123456789] build decimal numbers. Commas separate adjacent numbers.

Define unused characters by following quotation. (90r)R defines R as substitution for 90r.

Canvas is 320x320. Turtle begins at 160,160 bearing North.


Turtle Graphics using stack lang of single-character commands and quotations






No releases published


No packages published