LUA TURTLE

Loading...
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

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.

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)

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
heading()Returns current angle in degrees
isdown()Returns true if pen is down