ApasScript.

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.

forward Apas Cloud

Moves the turtle forward along its current heading, drawing a segment if the pen is down.

backward Apas Cloud

Moves the turtle backward along its current heading, drawing a segment if the pen is down.

left Apas Cloud

Turns the turtle counterclockwise by an angle in degrees.

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.

setheading Apas Cloud

Sets the turtle's heading directly, in degrees (0 = east, increasing = counterclockwise).

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().

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.

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.

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

fillColor Apas Cloud

Sets the colour endFill() fills with (the pen colour until set).

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.