| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{tikzlibraryturtle.code.tex} |
| 11 |
|
| 12 |
|
| 13 |
\tikzset{turtle/.style={/tikz/turtle/.cd,#1}}% |
| 14 |
|
| 15 |
% The current angle is stored in this key. |
| 16 |
\tikzset{turtle/direction/.code=\gdef\tikz@lib@turtle@dir{#1},turtle/direction=90}% |
| 17 |
|
| 18 |
% The current angle is stored in this key. |
| 19 |
\tikzset{turtle/distance/.initial=1cm}% |
| 20 |
|
| 21 |
% The to path options that are used to move the turtle |
| 22 |
\tikzset{turtle/how/.style=}% |
| 23 |
|
| 24 |
% Let the turtle jump home |
| 25 |
\tikzset{turtle/home/.style={/tikz/insert path={(0,0) [turtle/direction=90]}}}% |
| 26 |
|
| 27 |
% Moves the turtle forward by the given distance or, if no distance is |
| 28 |
% given, by turtle distance |
| 29 |
\tikzset{ |
| 30 |
turtle/forward/.default=\pgfkeysvalueof{/tikz/turtle/distance}, |
| 31 |
turtle/forward/.style={/tikz/insert path={to[/tikz/turtle/how]++({\tikz@lib@turtle@dir}:{#1})}} |
| 32 |
}% |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
% Moves the turtle backward by the given distance or, if no distance is |
| 37 |
% given, by turtle distance |
| 38 |
\tikzset{ |
| 39 |
turtle/back/.default=\pgfkeysvalueof{/tikz/turtle/distance}, |
| 40 |
turtle/back/.style={turtle forward={-(#1)}} |
| 41 |
}% |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
% Turns the turtle left by the given number of degrees |
| 46 |
\tikzset{ |
| 47 |
turtle/left/.default=90, |
| 48 |
turtle/left/.code={% |
| 49 |
\pgfmathparse{(#1)+(\tikz@lib@turtle@dir)}% |
| 50 |
\ifdim\pgfmathresult pt>360pt\relax% |
| 51 |
\pgfmathparse{\pgfmathresult-360}% |
| 52 |
\fi% |
| 53 |
\global\let\tikz@lib@turtle@dir\pgfmathresult |
| 54 |
} |
| 55 |
}% |
| 56 |
|
| 57 |
|
| 58 |
% Turns the turtle left by the given number of degrees |
| 59 |
\tikzset{ |
| 60 |
turtle/right/.default=90, |
| 61 |
turtle/right/.code={% |
| 62 |
\pgfmathparse{#1} |
| 63 |
\pgfmathparse{(\tikz@lib@turtle@dir)-\pgfmathresult}% |
| 64 |
\ifdim\pgfmathresult pt<0pt\relax% |
| 65 |
\pgfmathparse{\pgfmathresult+360}% |
| 66 |
\fi% |
| 67 |
\global\let\tikz@lib@turtle@dir\pgfmathresult |
| 68 |
} |
| 69 |
}% |
| 70 |
|
| 71 |
|
| 72 |
% Shortcuts: |
| 73 |
\tikzset{turtle/.cd, |
| 74 |
fd/.style={forward={#1}}, |
| 75 |
fd/.default=\pgfkeysvalueof{/tikz/turtle/distance}, |
| 76 |
bk/.style={back={#1}}, |
| 77 |
bk/.default=\pgfkeysvalueof{/tikz/turtle/distance}, |
| 78 |
lt/.style={left={#1}}, |
| 79 |
lt/.default=90, |
| 80 |
rt/.style={right={#1}}, |
| 81 |
rt/.default=90}% |
| 82 |
|
| 83 |
|
| 84 |
\endinput |