Turtle Graphics
These are Apas Cloud services: they run on our servers for a signed-in member. The examples below are shown already made; sign in to edit and run your own.
turtle Apas Cloud
Creates a turtle at the origin, heading east: turtle() for a fresh default-sized diagram, turtle(w, h) for a fresh sized one, or turtle(d) to draw into an existing diagram.
w (number) -- optional pixel width (fresh diagram only)
h (number) -- optional pixel height (fresh diagram only)
forward Apas Cloud
Moves the turtle forward along its current heading, drawing a segment if the pen is down.
t (turtle) --
dist (number) --
backward Apas Cloud
Moves the turtle backward along its current heading, drawing a segment if the pen is down.
t (turtle) --
dist (number) --
left Apas Cloud
Turns the turtle counterclockwise by an angle in degrees.
t (turtle) --
degrees (number) --
right Apas Cloud
Turns the turtle clockwise by an angle in degrees.
t (turtle) --
degrees (number) --
penup Apas Cloud
Lifts the turtle's pen -- subsequent moves reposition it without drawing.
pendown Apas Cloud
Lowers the turtle's pen -- subsequent moves draw again.
goto Apas Cloud
Jumps the turtle directly to (x, y), drawing a segment from its current position if the pen is down.
t (turtle) --
x (number) --
y (number) --
setheading Apas Cloud
Sets the turtle's heading directly, in degrees (0 = east, increasing = counterclockwise).
t (turtle) --
degrees (number) --
home Apas Cloud
Returns the turtle to the origin with heading reset to 0, drawing a segment there if the pen is down.
penColor Apas Cloud
Sets the turtle's pen colour for future segments: any CSS colour (a name such as "crimson", "#rrggbb", rgb(...), hsl(...)) or a colour value from rgb()/hsl()/mix().
t (turtle) --
color (string) --
heading Apas Cloud
The turtle's current heading, in degrees.
position Apas Cloud
The turtle's current position, as a point2d.
arc Apas Cloud
Sweeps the turtle along a true circular arc tangent to its current heading: positive angle curves left, negative curves right.
t (turtle) --
radius (number) --
angleDegrees (number) --
curveTo Apas Cloud
Draws a cubic Bezier curve from the turtle's current position, with control points and endpoint given as local (forward/left) offsets. The turtle exits along the curve's tangent direction.
t (turtle) --
c1dx (number) --
c1dy (number) --
c2dx (number) --
c2dy (number) --
edx (number) --
edy (number) --
pushState Apas Cloud
Pushes the turtle's position, heading, and pen state onto a stack -- pair with popState() to branch (e.g. drawing a fractal tree) and return.
popState Apas Cloud
Restores the turtle's position, heading, and pen state from the top of the stack pushState() built. Already-drawn shapes are unaffected.
penWidth Apas Cloud
Sets the width of the turtle's lines from now on (2 by default).
t (turtle) --
w (number) --
fillColor Apas Cloud
Sets the colour endFill() fills with (the pen colour until set).
t (turtle) --
color (colour) --
beginFill Apas Cloud
Starts recording a shape to fill: every point the turtle passes until endFill(), pen up or down, arcs and curves included.
endFill Apas Cloud
Fills the shape traced since beginFill(), under the lines drawn meanwhile.