Help

Using the Editor

Layout

The editor page has three areas: a code editor on the left (or top on mobile), a canvas on the right where the turtle draws, and a console at the bottom showing output and errors.

Controls

ButtonWhat it does
RunExecute your program. If animation speed is set to Instant, the drawing appears all at once. Otherwise, the turtle draws step by step.
StopStop a running animation. The drawing stays as-is.
StepAdvance the drawing by one operation. If you haven't run the program yet, Step will run it first and pause at the beginning so you can step through it.
ClearClear the canvas and reset everything. Your code stays in the editor.
Save & ShareSave your program and get a shareable link. Anyone with the link can view and run your program.

Speed Slider

Controls the animation speed. Instant (all the way left) draws everything immediately. Moving the slider right slows the animation down, letting you watch the turtle draw. Values are in milliseconds between drawing steps.

Gallery

The Gallery page shows example programs you can load into the editor and run. Click "Try it" on any example to open it.

Logo Language Reference

st-turtle implements a subset of the UCBLogo (Berkeley Logo) standard. All turtle graphics, arithmetic, control flow, procedures, and data operations are supported. Features not applicable to a web environment—file I/O, shell commands, keyboard/mouse input, terminal control, and workspace management—are intentionally excluded.

Logo is an educational programming language where you control a turtle that draws on a canvas. The turtle starts at the center facing north. Commands are case-insensitive.

Turtle Movement

CommandShortExampleDescription
FORWARD nFDFD 100Move forward n units
BACK nBKBK 50Move backward n units
RIGHT nRTRT 90Turn right n degrees
LEFT nLTLT 45Turn left n degrees
HOME HOMEReturn to center, heading north
SETXY x y SETXY 100 50Move to position (x, y)
SETX x SETX 100Set X coordinate
SETY y SETY -50Set Y coordinate
SETHEADING nSETHSETH 180Set heading (0=north, clockwise)
ARC angle radius ARC 360 50Draw an arc

Pen Control

CommandShortExampleDescription
PENUPPUPULift pen (stop drawing)
PENDOWNPDPDPut pen down (resume drawing)
SETPENCOLOR cSETPCSETPC 4Set pen color by index (0–15)
SETPC [255 0 0]Set pen color by RGB
SETPENSIZE nSETPSSETPS 3Set line width
SETBACKGROUND cSETBGSETBG 0Set background color by index (0–15)
SETBG [0 128 255]Set background color by RGB

Screen & Visibility

CommandShortDescription
CLEARSCREENCSClear canvas and reset turtle to home
CLEAN Clear drawings but keep turtle position
SHOWTURTLESTShow turtle cursor
HIDETURTLEHTHide turtle cursor

Text

CommandExampleDescription
LABEL textLABEL "helloDraw text on the canvas at the turtle's position
SETLABELHEIGHT nSETLABELHEIGHT 24Set the font size for LABEL

Boundary Modes

CommandDescription
WINDOWNo boundaries (default). Turtle can move anywhere.
WRAPTurtle wraps around to the opposite edge when it leaves the canvas.
FENCETurtle cannot move past the canvas edge. Raises an error if attempted.

Variables

CommandExampleDescription
MAKEMAKE "size 100Set a global variable
LOCALMAKELOCALMAKE "x 50Set a local variable (current scope)
LOCALLOCAL "xDeclare a local variable
:name:sizeRead a variable's value

Control Flow

CommandExampleDescription
REPEAT n [...]REPEAT 4 [FD 100 RT 90]Repeat commands n times
IF cond [...]IF :x > 10 [FD :x]Execute if condition is true
IFELSE cond [...] [...]IFELSE :x > 0 [FD :x] [BK :x]If/else branching
FOR [var start end] [...]FOR [i 1 10] [FD :i * 10 RT 90]Counted loop
FOR [var start end step] [...]FOR [i 1 20 2] [FD :i RT 90]Counted loop with step
WHILE [cond] [...]WHILE [:x < 100] [FD :x MAKE "x :x + 10]Loop while condition is true
UNTIL [cond] [...]UNTIL [:x >= 10] [MAKE "x :x + 1]Loop until condition becomes true
FOREVER [...]FOREVER [FD 1 RT 1]Loop forever (exit with STOP)
FOREACH list [...]FOREACH [1 2 3] [PRINT :?]Iterate over a list. Use :? for current item, :?rest for remaining.
REPCOUNTFD REPCOUNT * 10Current iteration number inside REPEAT (starts at 1)

Procedures

SyntaxDescription
TO name :param1 :param2 ... body ENDDefine a procedure
STOPExit a procedure early
OUTPUT valueReturn a value from a procedure (abbrev: OP)

Example:

TO SQUARE :size
  REPEAT 4 [FD :size RT 90]
END

SQUARE 100

Arithmetic & Comparison

OperatorDescription
+ - * / %Add, subtract, multiply, divide, remainder
= <>Equal, not equal
< > <= >=Comparisons
AND, OR, NOTLogical operators

Math Functions

FunctionDescription
SQRT, ABS, ROUND, INTSquare root, absolute value, round, truncate
SIN, COS, TANTrigonometry (degrees in, value out)
ASIN, ACOS, ATANInverse trig (value in, degrees out). ATAN also available as ARCTAN.
(ARCTAN x y)Two-argument arctangent: atan(y/x) in degrees
LN, LOG10, EXPNatural log, log base 10, e^x
POWER base expExponentiation
REMAINDER a b, MODULO a bRemainder / modulo
MAX a b, MIN a bMaximum, minimum
RANDOM nRandom integer from 0 to n–1
(RANDOM start end)Random integer from start to end (inclusive)
MINUS nNegation (use instead of "-1" in arguments)

List & Word Functions

FunctionDescription
FIRST, LASTFirst/last element of list or character of word
BUTFIRST (BF), BUTLAST (BL)All but first/last
COUNTLength of list or word
ITEM n listGet element at position n (1-indexed)
FPUT item listAdd item to front of list
LPUT item listAdd item to end of list
LIST a b ...Create a list
WORD a b ...Concatenate into a word
SENTENCE a b ... (SE)Flatten and combine into a list
MEMBER item listReturn tail of list/word starting at item (empty if not found)
ASCII wordCharacter code of first character
CHAR nCharacter from code point
UPPERCASE wordConvert to uppercase
LOWERCASE wordConvert to lowercase
SUBSTRING? a bIs a contained within b?

Queries & Predicates

FunctionDescription
XCOR, YCORTurtle's current X or Y coordinate
HEADINGTurtle's current heading
POSTurtle's position as [x y]
PENDOWNP (PENDOWN?)Is the pen down?
PENCOLOR (PC)Current pen color as [r g b]
BACKGROUND (BG)Current background color as [r g b]
PENSIZECurrent pen size
SHOWNP (SHOWN?)Is the turtle visible?
TOWARDS [x y]Heading towards a point
DEFINEDP (DEFINED?)Is a procedure defined?
NAMEP (NAME?)Is a variable defined?
NUMBER?, WORD?, LIST?, EMPTY?, MEMBER?Type and membership checks

Output

CommandDescription
PRINT (PR)Print a value to the console
SHOWPrint a value to the console
TYPEPrint a value to the console

Syntax Notes

  • Commands are case-insensitive: FD, fd, and Fd all work.
  • Variables are prefixed with : when reading: :size
  • String literals use " prefix: "hello. Use \ to include spaces: "hello\ world
  • Lists use square brackets: [1 2 3]
  • Comments start with ; and continue to end of line.
  • Booleans are the words "true and "false.
  • Use MINUS 1 instead of -1 when passing negative numbers as procedure arguments.
  • Programs are limited to 1,000,000 operations to prevent infinite loops.

Coordinate System

  • Origin (0, 0) is at the center of the canvas.
  • X increases to the right, Y increases upward.
  • Heading 0 = north, 90 = east, 180 = south, 270 = west.

Color Table

SETPENCOLOR and SETBACKGROUND accept a color index (0–15) or an [R G B] list with values from 0–255.

IndexColorIndexColor
0Black8Brown
1Blue9Tan
2Green10Forest
3Cyan11Aqua
4Red12Salmon
5Magenta13Purple
6Yellow14Orange
7White15Grey

Differences from UCBLogo

st-turtle follows the UCBLogo standard with these differences:

  • RGB values use 0–255 instead of UCBLogo’s 0–100 (percent saturation). This matches CSS/web conventions. Example: SETPC [255 0 0] for red.
  • Additional math functions: ABS, TAN, ASIN, ACOS, MAX, MIN are provided as extensions beyond UCBLogo’s built-in set. ATAN is an alias for the standard ARCTAN.

Getting Started

Draw a Square

REPEAT 4 [FD 100 RT 90]

Draw a Circle

REPEAT 360 [FD 1 RT 1]

Colorful Spiral

FOR [i 1 200] [
  SETPC REMAINDER :i 16
  FD :i
  RT 91
]

Define and Use a Procedure

TO POLYGON :sides :size
  REPEAT :sides [FD :size RT 360 / :sides]
END

POLYGON 6 80
PU FD 120 PD
POLYGON 8 60

Visit the Gallery for more examples including fractals, flowers, and recursive patterns.