\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/libraries/pgflibrarysnakes.code.tex,v 1.9 2005/10/13 10:12:31 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\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
    {\pgfpoint{.125\pgfsnakesegmentlength}{0pt}}
    {\pgfpoint{.1875\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfpoint{.3125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
  }
  \state{down}[switch if less than=.8125\pgfsnakesegmentlength to end down,
               width=.5\pgfsnakesegmentlength,
               next state=up]
  {
    \pgfpathcosine{\pgfpoint{.25\pgfsnakesegmentlength}{-\pgfsnakesegmentamplitude}}
    \pgfpathsine{\pgfpoint{.25\pgfsnakesegmentlength}{-\pgfsnakesegmentamplitude}}
  }               
  \state{up}[switch if less than=.8125\pgfsnakesegmentlength to end up,
             width=.5\pgfsnakesegmentlength,
             next state=down]
  {
    \pgfpathcosine{\pgfpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathsine{\pgfpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
  }               
  \state{end down}[width=.3125\pgfsnakesegmentlength,
                   next state=final]
  {
    \pgfpathcurveto
    {\pgfpoint{.125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfpoint{.1875\pgfsnakesegmentlength}{0pt}}
    {\pgfpoint{.3125\pgfsnakesegmentlength}{0pt}}
  }  
  \state{end up}[width=.3125\pgfsnakesegmentlength,
                 next state=final]
  {
    \pgfpathcurveto
    {\pgfpoint{.125\pgfsnakesegmentlength}{-\pgfsnakesegmentamplitude}}
    {\pgfpoint{.1875\pgfsnakesegmentlength}{0pt}}
    {\pgfpoint{.3125\pgfsnakesegmentlength}{0pt}}
  }  
  \state{final}
  { \pgfpathlineto{\pgfpoint{\pgfsnakeremainingdistance}{0pt}} }
}




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

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



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

\pgfdeclaresnake{saw}{initial}
{
  \state{initial}[width=\pgfsnakesegmentlength]
  {
    \pgfpathlineto{\pgfpoint{\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfpoint{\pgfsnakesegmentlength}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpoint{\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{\pgfpoint{\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
    {\pgfpoint{0pt}{.555\pgfsnakesegmentamplitude}}
    {\pgfpoint{0.11125\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfpoint{.25\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    \pgfpathcurveto
    {\pgfpoint{.38875\pgfsnakesegmentlength}{\pgfsnakesegmentamplitude}}
    {\pgfpoint{.5\pgfsnakesegmentlength}{.5\pgfsnakesegmentamplitude}}
    {\pgfpoint{.5\pgfsnakesegmentlength}{0\pgfsnakesegmentamplitude}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpoint{\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
      {\pgfpoint{-\pgfsnakecompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfsnakesegmentangle}{\pgfsnakecompleteddistance}}}%
    \pgfpatharc{\pgfsnakesegmentangle}{-\pgfsnakesegmentangle}{\pgfsnakecompleteddistance}%
  }
  \state{last}[width=0pt,next state=final]
  {
    \pgfpathmoveto{
      \pgfpointadd
      {\pgfpoint{-\pgfsnakecompleteddistance}{0pt}}%
      {\pgfpointpolar{\pgfsnakesegmentangle}{\pgfsnakecompleteddistance}}}%
    \pgfpatharc{\pgfsnakesegmentangle}{-\pgfsnakesegmentangle}{\pgfsnakecompleteddistance}%
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}



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

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


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

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



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

\pgfdeclaresnake{ticks}{ticks}
{
  \state{ticks}[width=\pgfsnakesegmentlength]
  {
    \pgfpathmoveto{\pgfpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgfsnakesegmentamplitude}}
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpoint{0pt}{\pgfsnakesegmentamplitude}}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgfsnakesegmentamplitude}}
    \pgfpathmoveto{\pgfpoint{\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{\pgfpoint{\pgfsnakeremainingdistance}{0pt}}
  }
}




% brace snakes
%
% Parameters: \pgfsnakesegmentamplitude

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



\endinput
