The TikZ and PGF Packages
Manual for version 3.1.10
TikZ Library turtle ¶
\usetikzlibrary[turtle] % ConTeXt
This little library defines some keys to create simple turtle graphics in the tradition of the Logo programming language. These commands are mostly for fun, but they can also be used for more “serious” business.
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=⟨keys⟩(no default) ¶
This key executes the ⟨keys⟩ with the current key path set to /tikz/turtle.
/tikz/turtle/home(no value) ¶
Places the turtle at the origin and lets it head upward.
/tikz/turtle/forward=⟨distance⟩ (default see text) ¶
/tikz/turtle/distance=⟨distance⟩ (no default, initially 1cm) ¶
/tikz/turtle/how(style, initially empty) ¶
Makes the turtle move forward by the given ⟨distance⟩. If no ⟨distance⟩ is specified, the current value of the following key is used:
The default distance by which the turtle advances.
“Moving forward the turtle” actually means that, relative to the current last point on the path, a point at the given ⟨distance⟩ in the direction the turtle is currently heading is computed. Then, the operation to[turtle/how] is used to extend the path to this point.
This style can set up the to path used by turtles. By setting this style you can change the to-path:
/tikz/turtle/fd(no value) ¶
An abbreviation for the forward key.
/tikz/turtle/back=⟨distance⟩ (default see text) ¶
This has the same effect as a turtle/forward for the negated ⟨distance⟩ value.
/tikz/turtle/bk(no value) ¶
An abbreviation for the back key.
/tikz/turtle/left=⟨angle⟩ (default 90) ¶
Turns the turtle left by the given angle.
/tikz/turtle/lt(no value) ¶
An abbreviation for the left key.
/tikz/turtle/right=⟨angle⟩ (default 90) ¶
Turns the turtle right by the given angle.
/tikz/turtle/rt(no value) ¶
An abbreviation for the right key.
Turtle graphics are especially nice in conjunction with the \foreach statement: