LUA TURTLE

Commands

Use ↑ ↓ to select a command, to jump between sections.

Movement

  • forward(n)Move forward n pixels. Alias: fd
  • back(n)Move backward n pixels. Alias: bk
  • left(degrees)Turn left. Alias: lt
  • right(degrees)Turn right. Alias: rt
  • setpos(x, y)Move to coordinates (x, y)
  • setheading(angle)Face a direction (0=east, 90=north). Alias: seth
  • home()Return to center, face east
  • setx(x)Set x coordinate, keep y
  • sety(y)Set y coordinate, keep x
  • teleport(x, y)Jump to position instantly, no drawing

Pen

  • penup()Stop drawing. Alias: pu
  • pendown()Start drawing. Alias: pd
  • pensize(n)Set line width
  • pencolor(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 color
  • color("red", "blue")Set pen and fill color independently

Shapes

  • circle(radius)Draw a full circle
  • circle(radius, extent)Arc: extent in degrees

Fill

  • begin_fill()Start recording a filled shape
  • end_fill()Fill the shape drawn since begin_fill
  • filling()Returns true if currently filling
  • fillcolor(r, g, b)Set fill color
  • dot(size)Draw a filled circle at turtle's position
  • dot(size, "red")Draw a dot with a specific color

Text

  • write(text)Write text at turtle's position
  • write(text, move, align, font)align: "left", "center", "right"; font: {family, size}

Canvas

  • bgcolor(r, g, b)Set background color
  • bgcolor("name")Set background color by name
  • screen_width()Returns canvas width in pixels
  • screen_height()Returns canvas height in pixels
  • clear()Erase drawing, keep turtle position
  • reset()Erase drawing and reset turtle to start
  • undo()Undo the last command
  • setundobuffer(n)Set max undo history length
  • speed(n)0=instant, 1=slowest, 10=fastest

Turtle

  • hideturtle()Hide the turtle. Alias: ht
  • showturtle()Show the turtle. Alias: st
  • stamp()Stamp turtle shape; returns id
  • clearstamp(id)Remove a stamp
  • clearstamps(n)Remove last n stamps; omit n to clear all
  • Turtle()Create a second turtle with all the same methods

State Queries

  • position()Returns x, y coordinates
  • xcor() / ycor()Returns x or y coordinate
  • heading()Returns current angle in degrees
  • isdown()Returns true if pen is down
  • isvisible()Returns true if turtle is visible
  • distance(x, y)Returns distance to point
  • towards(x, y)Returns angle towards point

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

Terminal