% Copyright 2006 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/libraries/pgflibrarysnakes.code.tex,v 1.15 2007/03/09 17:49:32 tantau Exp $


\newdimen\pgfsnakesegmentamplitude
\newdimen\pgfsnakesegmentlength
\def\pgfsnakesegmentangle{45}
\def\pgfsnakesegmentobjectlength{\pgfsnakesegmentamplitude}
\def\pgfsnakesegmentaspect{0.5}

\pgfsnakesegmentlength=10pt
\pgfsnakesegmentamplitude=2.5pt



% snake snake
%
% This snake produces a hopefully optically pleasing squiggly snake. 
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentlength

\pgfdeclaresnake{snake}{initial}
{
  \state{initial}[switch if less than=+.625\pgfsnakesegmentlength to final,
                  width=+.3125\pgfsnakesegmentlength,
                  next state=down]
  { 
    \pgfpathcurveto
    {\pgfqpoint{.125\pgfsnakesegmentlength}{0pt}}
    {\pgfqpoint{.1875\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.3125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
  }
  \state{down}[switch if less than=+.8125\pgfsnakesegmentlength to end down,
               width=+.5\pgfsnakesegmentlength,
               next state=up]
  {
    \pgfpathcosine{\pgfqpoint{.25\pgfsnakesegmentlength}{-1\pgfsnakesegmentamplitude}}
    \pgfpathsine{\pgfqpoint{.25\pgfsnakesegmentlength}{-1\pgfsnakesegmentamplitude}}
  }               
  \state{up}[switch if less than=+.8125\pgfsnakesegmentlength to end up,
             width=+.5\pgfsnakesegmentlength,
             next state=down]
  {
    \pgfpathcosine{\pgfqpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathsine{\pgfqpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
  }               
  \state{end down}[width=+.3125\pgfsnakesegmentlength,
                   next state=final]
  {
    \pgfpathcurveto
    {\pgfqpoint{.125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.1875\pgfsnakesegmentlength}{0pt}}
    {\pgfqpoint{.3125\pgfsnakesegmentlength}{0pt}}
  }  
  \state{end up}[width=+.3125\pgfsnakesegmentlength,
                 next state=final]
  {
    \pgfpathcurveto
    {\pgfqpoint{.125\pgfsnakesegmentlength}{-\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.1875\pgfsnakesegmentlength}{0pt}}
    {\pgfqpoint{.3125\pgfsnakesegmentlength}{0pt}}
  }  
  \state{final}
  { \pgfpathlineto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}} }
}




% zigzag snake
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentlength

\pgfdeclaresnake{zigzag}{up}
{
  \state{up}[width=+.5\pgfsnakesegmentlength,%
             next state=down]
  {
    \pgfpathlineto{\pgfqpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{.5\pgfsnakesegmentlength}{0pt}}
  }
  \state{down}[width=+.5\pgfsnakesegmentlength,%
               next state=up]
  {
    \pgfpathlineto{\pgfqpoint{.25\pgfsnakesegmentlength}{-\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{.5\pgfsnakesegmentlength}{0pt}}
  }
  \state{final}
  { \pgfpathlineto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}} }
}



% saw snake
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentlength

\pgfdeclaresnake{saw}{initial}
{
  \state{initial}[width=+\pgfsnakesegmentlength]
  {
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentlength}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}


% coil snake
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentlength,

\pgfdeclaresnake{coil}{coil}
{
  \state{coil}[switch if less than=%
    1.5\pgfsnakesegmentlength+%
    \pgfsnakesegmentaspect\pgfsnakesegmentamplitude+%
    \pgfsnakesegmentaspect\pgfsnakesegmentamplitude to last,
               width=+\pgfsnakesegmentlength]
  {
    \pgfpathcurveto
    {\pgfpoint@oncoil{0    }{ 0.555}{1}}
    {\pgfpoint@oncoil{0.445}{ 1    }{2}}
    {\pgfpoint@oncoil{1    }{ 1    }{3}}
    \pgfpathcurveto
    {\pgfpoint@oncoil{1.555}{ 1    }{4}}
    {\pgfpoint@oncoil{2    }{ 0.555}{5}}
    {\pgfpoint@oncoil{2    }{ 0    }{6}}
    \pgfpathcurveto
    {\pgfpoint@oncoil{2    }{-0.555}{7}}
    {\pgfpoint@oncoil{1.555}{-1    }{8}}
    {\pgfpoint@oncoil{1    }{-1    }{9}}
    \pgfpathcurveto
    {\pgfpoint@oncoil{0.445}{-1    }{10}}
    {\pgfpoint@oncoil{0    }{-0.555}{11}}
    {\pgfpoint@oncoil{0    }{ 0    }{12}}
  }
  \state{last}[width=.5\pgfsnakesegmentlength+%
    \pgfsnakesegmentaspect\pgfsnakesegmentamplitude+%
    \pgfsnakesegmentaspect\pgfsnakesegmentamplitude,next state=final]
  {
    \pgfpathcurveto
    {\pgfpoint@oncoil{0    }{ 0.555}{1}}
    {\pgfpoint@oncoil{0.445}{ 1    }{2}}
    {\pgfpoint@oncoil{1    }{ 1    }{3}}
    \pgfpathcurveto
    {\pgfpoint@oncoil{1.555}{ 1    }{4}}
    {\pgfpoint@oncoil{2    }{ 0.555}{5}}
    {\pgfpoint@oncoil{2    }{ 0    }{6}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}

\def\pgfpoint@oncoil#1#2#3{%
  \pgf@x=#1\pgfsnakesegmentamplitude%
  \pgf@x=\pgfsnakesegmentaspect\pgf@x%
  \pgf@y=#2\pgfsnakesegmentamplitude%
  \pgf@xa=0.083333333333\pgfsnakesegmentlength%
  \advance\pgf@x by#3\pgf@xa%
}


% bumps snake
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentlength

\pgfdeclaresnake{bumps}{initial}
{
  \state{initial}[width=+.5\pgfsnakesegmentlength]
  {
    \pgfpathcurveto
    {\pgfqpoint{0pt}{.555\pgfsnakesegmentamplitude}}
    {\pgfqpoint{0.11125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathcurveto
    {\pgfqpoint{.38875\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.5\pgfsnakesegmentlength}{.5\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.5\pgfsnakesegmentlength}{0\pgfsnakesegmentamplitude}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}



% expanding waves snake
%
% Parameters: \pgfsnakesegmentangle, \pgfsnakesegmentlength

\pgfdeclaresnake{expanding waves}{initial}
{
  \state{initial}[width=+\pgfsnakesegmentlength,next state=wave]
  {}

  \state{wave}[switch if less than=+\pgfsnakesegmentlength to last,
               width=+\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfsnakecompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfsnakesegmentangle}{+\pgfsnakecompleteddistance}}}%
    \pgfpatharc{\pgfsnakesegmentangle}{-\pgfsnakesegmentangle}{+\pgfsnakecompleteddistance}%
  }
  \state{last}[width=+0pt,next state=final]
  {
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfsnakecompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfsnakesegmentangle}{+\pgfsnakecompleteddistance}}}%
    \pgfpatharc{\pgfsnakesegmentangle}{-\pgfsnakesegmentangle}{+\pgfsnakecompleteddistance}%
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}



% waves snake
%
% Parameters: \pgfsnakesegmentangle, \pgfsnakesegmentlength

\pgfdeclaresnake{waves}{wave}
{
  \state{wave}[width=\pgfsnakesegmentlength]
  {
    \pgftransformxshift{+\pgfsnakesegmentlength}
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfqpoint{-\pgfsnakesegmentobjectlength}{0pt}}%
      {\pgfpointpolar{\pgfsnakesegmentangle}{+\pgfsnakesegmentobjectlength}}}%
    \pgfpatharc{\pgfsnakesegmentangle}{-\pgfsnakesegmentangle}{+\pgfsnakesegmentobjectlength}%
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}


% triangle snakes
%
% Parameters: \pgfsnakesegmentlength, \pgfsnakeobjectsize, \pgfsnakesegmentamplitude

\pgfdeclaresnake{triangles}{triangle}
{
  \state{triangle}[switch if less than=+\pgfsnakesegmentlength to last,
                   width=+\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{0pt}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathclose
  }
  \state{last}[width=+\pgfsnakesegmentobjectlength,next state=final]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{0pt}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathclose
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}



% crosses snakes
%
% Parameters: \pgfsnakesegmentlength, \pgfsnakeobjectsize, \pgfsnakesegmentamplitude

\pgfdeclaresnake{crosses}{crosses}
{
  \state{crosses}[switch if less than=+\pgfsnakesegmentlength to last,
                   width=+\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{-\pgfsnakesegmentamplitude}}
    \pgfpathmoveto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{\pgfsnakesegmentamplitude}}
  }
  \state{last}[width=\pgfsnakesegmentobjectlength,next state=final]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{-1\pgfsnakesegmentamplitude}}
    \pgfpathmoveto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{\pgfsnakesegmentobjectlength}{\pgfsnakesegmentamplitude}}
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}



% ticks snakes
%
% Parameters: \pgfsnakesegmentlength, \pgfsnakesegmentamplitude

\pgfdeclaresnake{ticks}{ticks}
{
  \state{ticks}[width=+\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}


% border snake
%
% Parameters: \pgfsnakesegmentlength, \pgfsnakesegmentamplitude, \pgfsnakesegmentangle

\pgfdeclaresnake{border}{tick}
{
  \state{tick}[switch if less than=+\pgfsnakesegmentlength to last,
               width=+\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpointpolar{\pgfsnakesegmentangle}{+\pgfsnakesegmentamplitude}}
  }
  \state{last}[width=+\pgfsnakesegmentamplitude,next state=final]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpointpolar{\pgfsnakesegmentangle}{+\pgfsnakesegmentamplitude}}
  }  
  \state{final}
  {
    \pgfpathmoveto{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}




% brace snakes
%
% Parameters: \pgfsnakesegmentamplitude

\pgfdeclaresnake{brace}{brace}
{
  \state{brace}[width=+\pgfsnakeremainingdistance,next state=final]
  {
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathcurveto
    {\pgfqpoint{.15\pgfsnakesegmentamplitude}{.3\pgfsnakesegmentamplitude}}
    {\pgfqpoint{.5\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
    {\pgfqpoint{\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
    {
      \pgftransformxshift{+\pgfsnakesegmentaspect\pgfsnakeremainingdistance}
      \pgfpathlineto{\pgfqpoint{-\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{-.5\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
      {\pgfqpoint{-.15\pgfsnakesegmentamplitude}{.7\pgfsnakesegmentamplitude}}
      {\pgfqpoint{0\pgfsnakesegmentamplitude}{1\pgfsnakesegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{.15\pgfsnakesegmentamplitude}{.7\pgfsnakesegmentamplitude}}
      {\pgfqpoint{.5\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
      {\pgfqpoint{\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
    }
    {
      \pgftransformxshift{+\pgfsnakeremainingdistance}
      \pgfpathlineto{\pgfqpoint{-\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
      \pgfpathcurveto
      {\pgfqpoint{-.5\pgfsnakesegmentamplitude}{.5\pgfsnakesegmentamplitude}}
      {\pgfqpoint{-.15\pgfsnakesegmentamplitude}{.3\pgfsnakesegmentamplitude}}
      {\pgfqpoint{0pt}{0pt}}
    }
  }
  \state{final}
  {}
}



% bent snake
%
% A snake that looks like someone bent the line a bit.
%
% Parameters: \pgfsnakesegmentamplitude, \pgfsnakesegmentaspect

\pgfdeclaresnake{bent}{bent}
{
  \state{bent}[width=+\pgfsnakeremainingdistance,next state=final]
  {
    \pgfpathcurveto
    {\pgfqpoint{\pgfsnakesegmentaspect\pgfsnakeremainingdistance}{\pgfsnakesegmentamplitude}}
    {\pgfpointadd{\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
       {\pgfqpoint{-\pgfsnakesegmentaspect\pgfsnakeremainingdistance}{\pgfsnakesegmentamplitude}}}
    {\pgfqpoint{\pgfsnakeremainingdistance}{0pt}}
  }
  \state{final}
  {}
}



\endinput
