LUA TURTLE

Terminal
100%

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)Fraction of a circle: 1/4, 1/2, etc.
arc(radius, degrees)Draw an arc of the given degrees

Fill

begin_fill()Start recording a filled shape
end_fill()Fill the shape drawn since begin_fill
setfillcolor(r, g, b)Set fill color (defaults to pen color)
dot(size)Draw a filled circle at turtle's position
dot(size, "red")Draw a dot with a specific color

Text

text("hello")Write text at turtle's position
text("hello", font, size)Custom font and size: text("hi", "monospace", 24)
text("hello", font, size, align)Align: "left" (default), "center", or "right"

Canvas

bgcolor(r, g, b)Set background color
clear()Erase drawing, keep turtle position
reset()Erase drawing and reset turtle to start
speed(n)Animation speed: 0=instant, 1=slow, 10=fast

State Queries

position()Returns x, y coordinates
xcor()Returns x coordinate
ycor()Returns y coordinate
heading()Returns current angle in degrees
isdown()Returns true if pen is down
filling()Returns true if currently filling
isvisible()Returns true if turtle is visible
hideturtle()Hide the turtle
showturtle()Show the turtle
distance(x, y)Returns distance to point
towards(x, y)Returns angle towards point