technique

turtle graphics

Drive the plotter by issuing forward/turn/circle turtle commands that accumulate into a drawable path, rather than specifying coordinates directly.

Run it

Driving a turtle with forward, turn and circle relative motion: forward() and turn() never touch an absolute (x, y) · approximating an arc from repeated "turn a little, move a little" steps · a recursive procedure composes the same two calls at a shrinking distance
What it looks like when it goes wrong (3)
  • At 4° per step the heading barely changes across the twelve-step loop, so instead of closing into a polygon the trace holds almost one direction the whole way through and drifts straight off the visible frame. Heading is cumulative — one turn that is slightly wrong early compounds into every later segment, because forward() only ever knows "keep going the way I am currently facing", never where the polygon was supposed to close.
  • circle() has no curve primitive of its own — it only ever chains straight forward() calls between small turns. With 3 segments the loop off the polygon is built from three long straight chords meeting at sharp corners, not a smooth curl.
  • A 180° turn after every forward() just reverses the heading, so each step retraces the previous one instead of turning a corner. The polygon loop collapses onto a single back-and-forth line instead of closing — a common surprise for anyone assuming "turn" means "turn a corner" rather than "rotate by exactly this many degrees, including all the way around".

Clean-room implementation — written from the described algorithm, not from source. Reuse policy

What it is

Turtle graphics means describing a path as a sequence of relative moves — forward this far, turn this many degrees, sweep an arc — issued to a stateful pen that remembers its own position and heading. The accumulated trace of those moves is the drawing; nothing is ever written down as an absolute (x, y).

How it works

  1. Create a turtle (axi.Turtle()).
  2. Issue relative commands, interpreted against the turtle’s current position and heading, never an absolute coordinate.
  3. Each command appends a segment or arc to the trace.
  4. Read the finished trace off as a path and pass it downstream.

The example turns with turtle.circle(-1, 90, 36) — an arc rather than a hard corner, taken from wherever the turtle currently sits.

Parameters & tuning

Distance and turn angle are the knobs that shape the path. circle()’s step count trades curve smoothness against path length: too few segments and a turn shows as facets, not a curve.

What matters more is structural: because every command is relative to the turtle’s current position and heading, a forward/turn procedure can call itself at a smaller distance and compose into a fractal without ever computing where a branch will land — why the interface suits recursive and fractal paths particularly well.

Because heading carries forward between calls, one wrong turn early throws off every segment after it; an absolute-coordinate path keeps a bad point local to itself.

Where it’s been used

Fogleman’s axi, an unofficial control library for the AxiDraw V3, ships this as its turtle interface, and the dragon curve is the example it ships to demonstrate it.

Variants & neighbours

Lindenmayer systems don’t replace this, they generate the command sequence a different way: a grammar gets expanded into a symbol string, and that string — not hand-written calls — is what gets walked onto the same forward/turn actions. Downstream of either, path drawing-order optimization, the page-fit transform and constant-acceleration motion planning all operate on the trace a turtle has already produced — reordering paths, rescaling the finished drawing, planning the pen’s physical velocity — none of them deciding the path’s shape.

Go deeper

Connected to

Pioneered by: Michael Fogleman

Requires: L-system

Try it yourself

An L-system and the dragon curve both end up issuing the same turtle forward and turn commands. What's actually different between them?

Only where the command sequence comes from. The dragon curve can compute each turn on the fly from the loop index — no string to rewrite, no grammar. An L-system instead expands a grammar into a symbol string ahead of time and then walks that string onto the turtle. The turtle itself doesn't know or care which one produced its instructions.


Revision 2 · 1 source · Something wrong? Tell us.