PGF/TikZ Manual | PGFplots | TikZ Editor

TikZ and PGF Manual

Libraries

77 Turtle Graphics Library

Even though the turtle keys looks like an option, it uses the insert path option internally to produce a path.

The basic drawing model behind the turtle graphics is very simple: There is a (virtual) turtle that crawls around the page, thereby extending the path. The turtle always heads in a certain direction. When you move the turtle forward, you extend the path in that direction; turning the turtle just changes the direction, it does not cause anything to be drawn.

The turtle always moves relative to the last current point of the path and you can mix normal path commands with turtle commands. However, the direction of the turtle is managed independently of other path commands.

  • /tikz/turtle/home(no value)

  • Places the turtle at the origin and lets it head upward.

  • /tikz/turtle/fd(no value)

  • An abbreviation for the forward key.

Turtle graphics are especially nice in conjunction with the \foreach statement:

(-tikz- diagram)

\usetikzlibrary {turtle}
\tikz \filldraw [thick,blue,fill=blue!20]
[turtle=home]
\foreach \i in {1,...,5}
{
[turtle={forward,right=144}]
};