summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryturtle.code.tex
blob: c0306b4d3045754127150876ba5991c9b2cf32c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
% Copyright 2008 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryturtle.code.tex,v 1.3 2008/06/18 23:34:49 tantau Exp $


\tikzset{turtle/.style={/tikz/turtle/.cd,#1}}

% The current angle is stored in this key.
\tikzset{turtle/direction/.code=\gdef\tikz@lib@turtle@dir{#1},turtle/direction=90}

% The current angle is stored in this key.
\tikzset{turtle/distance/.initial=1cm}

% The to path options that are used to move the turtle
\tikzset{turtle/how/.style=}

% Let the turtle jump home
\tikzset{turtle/home/.style={/tikz/insert path={(0,0) [turtle/direction=90]}}}

% Moves the turtle forward by the given distance or, if no distance is
% given, by turtle distance
\tikzset{
  turtle/forward/.default=\pgfkeysvalueof{/tikz/turtle/distance},
  turtle/forward/.style={/tikz/insert path={to[/tikz/turtle/how]++(\tikz@lib@turtle@dir:#1)}}
}



% Moves the turtle backward by the given distance or, if no distance is
% given, by turtle distance
\tikzset{
  turtle/back/.default=\pgfkeysvalueof{/tikz/turtle/distance},
  turtle/back/.style={turtle forward=-#1}
}



% Turns the turle left by the given number of degrees
\tikzset{
  turtle/left/.default=90,
  turtle/left/.code={%
    \pgfmathparse{#1+\tikz@lib@turtle@dir}%
    \ifdim\pgfmathresult pt>360pt\relax%
      \pgfmathparse{\pgfmathresult-360}%
    \fi%
    \global\let\tikz@lib@turtle@dir\pgfmathresult  
  }
}


% Turns the turle left by the given number of degrees
\tikzset{
  turtle/right/.default=90,
  turtle/right/.code={%
    \pgfmathparse{#1}
    \pgfmathparse{\tikz@lib@turtle@dir-\pgfmathresult}%
    \ifdim\pgfmathresult pt<0pt\relax%
      \pgfmathparse{\pgfmathresult+360}%
    \fi%
    \global\let\tikz@lib@turtle@dir\pgfmathresult  
  }
}


% Shortcuts:
\tikzset{turtle/.cd,
  fd/.style={forward=#1},
  fd/.default=\pgfkeysvalueof{/tikz/turtle/distance},
  bk/.style={back=#1},
  bk/.default=\pgfkeysvalueof{/tikz/turtle/distance},
  lt/.style={left=#1},
  lt/.default=90,
  rt/.style={right=#1},
  rt/.default=90}


\endinput