% 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
