Commands
Use ↑ ↓ to select a command, to jump between sections.
Movement
forward(n)Move forward n pixels. Alias: fdback(n)Move backward n pixels. Alias: bkleft(degrees)Turn left. Alias: ltright(degrees)Turn right. Alias: rtsetpos(x, y)Move to coordinates (x, y)setheading(angle)Face a direction (0=east, 90=north). Alias: sethhome()Return to center, face eastsetx(x)Set x coordinate, keep ysety(y)Set y coordinate, keep xteleport(x, y)Jump to position instantly, no drawing
Pen
penup()Stop drawing. Alias: pupendown()Start drawing. Alias: pdpensize(n)Set line widthpencolor(r, g, b)Set color with RGB (0–1 or 0–255)pencolor("name")Set color by name: "red", "blue", "gold", etc.color("red")Set both pen and fill colorcolor("red", "blue")Set pen and fill color independently
Shapes
circle(radius)Draw a full circlecircle(radius, extent)Arc: extent in degrees
Fill
begin_fill()Start recording a filled shapeend_fill()Fill the shape drawn since begin_fillfilling()Returns true if currently fillingfillcolor(r, g, b)Set fill colordot(size)Draw a filled circle at turtle's positiondot(size, "red")Draw a dot with a specific color
Text
write(text)Write text at turtle's positionwrite(text, move, align, font)align: "left", "center", "right"; font: {family, size}
Canvas
bgcolor(r, g, b)Set background colorbgcolor("name")Set background color by namescreen_width()Returns canvas width in pixelsscreen_height()Returns canvas height in pixelsclear()Erase drawing, keep turtle positionreset()Erase drawing and reset turtle to startundo()Undo the last commandsetundobuffer(n)Set max undo history lengthspeed(n)0=instant, 1=slowest, 10=fastest
Graphing
graph(left, bottom, right, top)Use graph coordinates: this rectangle, one unit the same length both waysgraph(left, bottom, right, top, "stretch")Graph coordinates stretched to fill the canvasgraph(left, bottom, right, top, box)A graph in a box: {x, y, width, height, units}; the rest of the canvas keeps its coordinatessetworldcoordinates(left, bottom, right, top)Make the canvas edges these coordinates, as in Pythonaxes()Draw graph paper: grid, axes and numbersaxes(xstep, ystep, xname, yname)Grid lines every xstep and ystep; name the axesplot(f, color)Draw the curve y = f(x) across the graphmark(x, y, color, label)Draw a dot at (x, y), with a labelg:plot(f, color)Draw on graph g even after a newer graph(); g:axes() and g:mark(x, y) toog:tocanvas(x, y)The canvas point at (x, y) on graph g, for the turtle: setpos(g:tocanvas(2, 3))g:tograph(x, y)The point on graph g at canvas point (x, y), such as a click
Interaction
onclick(f)Call f(x, y) when the canvas is clickedondrag(f)Call f(x, y) as the pointer drags across the canvasonrelease(f)Call f(x, y) when the pointer lets go of the canvasonkeypress(f, key)Call f when key is pressed; leave out key for any keyonkeyrelease(f, key)Call f when key is let go. Alias: onkeydone()Keep answering clicks, keys and controls until Stop; code after it waits. Alias: mainloopslider(options)A slider: {label, min, max, value, step, x, y, width, onchange}; read s.valuebutton(options)A button: {label, x, y, width, onclick}toggle(options)An on/off switch: {label, value, x, y, onchange}; read t.valueradio(options)Radio buttons: {label, options, value, x, y, onchange}; read r.valuetextfield(options)A text box: {label, value, x, y, width, onchange, onsubmit}; read f.valuecontrol.valueRead or set a control's value as the program runs; control.label likewisecontrol:remove()Take a control off the canvas
Turtle
hideturtle()Hide the turtle. Alias: htshowturtle()Show the turtle. Alias: ststamp()Stamp turtle shape; returns idclearstamp(id)Remove a stampclearstamps(n)Remove last n stamps; omit n to clear allTurtle()Create a second turtle with all the same methods
State Queries
position()Returns x, y coordinatesxcor() / ycor()Returns x or y coordinateheading()Returns current angle in degreesisdown()Returns true if pen is downisvisible()Returns true if turtle is visibledistance(x, y)Returns distance to pointtowards(x, y)Returns angle towards point
No commands match
Turn on Demos above to see this command in action.
100%
Drag or scroll to pan
Pinch or Ctrl/⌘+scroll to zoom
Drag to pan
Pinch to zoom