127 lines
5.7 KiB
TeX
127 lines
5.7 KiB
TeX
\usetikzlibrary{decorations.pathreplacing}
|
|
\def\pgfdecorationgrowthstart{0cm}
|
|
\def\pgfdecorationgrowthendsizelist{0cm}
|
|
\def\pgfdecorationgrowthwavelengthlist{0cm}
|
|
\def\pgfdecorationgrowthendstepslist{1}
|
|
\def\pgfdecorationgrowthendstep{1}
|
|
\newif\ifpgfdecorationgrowthsine
|
|
\newif\ifpgfdecorationgrowthcosine
|
|
\newif\ifpgfdecorationonewavelength
|
|
\pgfdecorationgrowthcosinefalse
|
|
\pgfdecorationgrowthsinetrue
|
|
\pgfkeys{%
|
|
/pgf/decoration/.cd,
|
|
growth start size/.initial=0.5cm,
|
|
growth end size/.initial=3cm,
|
|
growth end steps/.initial=1,
|
|
growth wave length/.initial=3pt,
|
|
growth sine/.code={\pgfdecorationgrowthsinetrue\pgfdecorationgrowthcosinefalse},
|
|
growth cosine/.code={\pgfdecorationgrowthsinefalse\pgfdecorationgrowthcosinetrue}
|
|
}
|
|
\def\pgfdecorationgrowthsetup{%
|
|
\global\edef\pgfdecorationgrowthstart{\pgfkeysvalueof{/pgf/decoration/growth start size}}%
|
|
\global\edef\pgfdecorationgrowthendsizelist{\pgfkeysvalueof{/pgf/decoration/growth end size}}%
|
|
\global\edef\pgfdecorationgrowthendstepslist{\pgfkeysvalueof{/pgf/decoration/growth end steps}}%
|
|
\global\edef\pgfdecorationgrowthwavelengthlist{\pgfkeysvalueof{/pgf/decoration/growth wave length}}%
|
|
}
|
|
|
|
\def\pgfdecorationgrowthsteps{1} % To keep track of steps from ending
|
|
\def\pgfdecorationliststeps{2} % To keep track of list items from ending, has to start from 2
|
|
|
|
\pgfdeclaredecoration{growth wave}{initial}%
|
|
{
|
|
\state{initial}[width=0pt,next state=first] {%
|
|
\pgfdecorationgrowthsetup%
|
|
\pgfpathlineto{\pgfqpoint{0pt}{0pt}}%
|
|
\global\edef\pgfdecorationgrowthsteps{0}%
|
|
\global\edef\pgfdecorationliststeps{2}%
|
|
\foreach \endsize in \pgfdecorationgrowthendsizelist {%
|
|
\global\edef\pgfdecorationgrowthendsize{\endsize}%
|
|
\breakforeach%
|
|
}%
|
|
\foreach \growthstep in \pgfdecorationgrowthendstepslist {%
|
|
\global\edef\pgfdecorationgrowthendstep{\growthstep}%
|
|
\breakforeach%
|
|
}%
|
|
\foreach \wavelength in \pgfdecorationgrowthwavelengthlist {%
|
|
\global\edef\pgfdecorationgrowthwavelength{\wavelength}%
|
|
\breakforeach%
|
|
}%
|
|
\pgfmathparse{(\pgfdecorationgrowthendsize - \pgfdecorationgrowthstart) * 2 * %
|
|
\pgfdecorationgrowthwavelength / ( \pgfdecoratedremainingdistance * \pgfdecorationgrowthendstep)}%
|
|
\global\edef\pgfdecorationgrowth{\pgfmathresult}%
|
|
}%
|
|
|
|
\state{first}[width=2*\pgfdecorationgrowthwavelength,next state=second] {%
|
|
\pgfdecorationgrowthstepcounters%
|
|
\pgfmathparse{\pgfdecorationgrowthstart + \pgfdecorationgrowthsteps * \pgfdecorationgrowth}%
|
|
% The wave starts
|
|
\ifpgfdecorationgrowthsine%
|
|
\pgfpathsine{\pgfqpoint{\pgfdecorationgrowthwavelength}{\pgfmathresult pt}}%
|
|
\pgfpathcosine{\pgfqpoint{\pgfdecorationgrowthwavelength}{-\pgfmathresult pt}}%
|
|
\fi%
|
|
\ifpgfdecorationgrowthcosine%
|
|
\pgfpathsine{\pgfqpoint{\pgfdecorationgrowthwavelength}{-\pgfmathresult pt}}%
|
|
\pgfpathcosine{\pgfqpoint{\pgfdecorationgrowthwavelength}{\pgfmathresult pt}}%
|
|
\fi%
|
|
\pgfdecorationgrowthstateend%
|
|
}%
|
|
|
|
\state{second}[width=2*\pgfdecorationgrowthwavelength,next state=first] {%
|
|
\pgfdecorationgrowthstepcounters%
|
|
\pgfmathparse{\pgfdecorationgrowthstart + \pgfdecorationgrowthsteps * \pgfdecorationgrowth}%
|
|
% The wave continues
|
|
\ifpgfdecorationgrowthsine%
|
|
\pgfpathsine{\pgfqpoint{\pgfdecorationgrowthwavelength}{-\pgfmathresult pt}}%
|
|
\pgfpathcosine{\pgfqpoint{\pgfdecorationgrowthwavelength}{\pgfmathresult pt}}%
|
|
\fi%
|
|
\ifpgfdecorationgrowthcosine%
|
|
\pgfpathsine{\pgfqpoint{\pgfdecorationgrowthwavelength}{\pgfmathresult pt}}%
|
|
\pgfpathcosine{\pgfqpoint{\pgfdecorationgrowthwavelength}{-\pgfmathresult pt}}%
|
|
\fi%
|
|
\pgfdecorationgrowthstateend%
|
|
}
|
|
\state{final} {%
|
|
\pgfpathlineto{\pgfpointdecoratedpathlast}%
|
|
}%
|
|
}
|
|
\def\pgfdecorationgrowthstateend{%
|
|
\pgfmathadd{\pgfdecorationgrowthsteps}{1}%
|
|
\global\edef\pgfdecorationgrowthsteps{\pgfmathresult} % Redefine the steps counter, globally.
|
|
}
|
|
|
|
\def\pgfdecorationgrowthstepcounters{%
|
|
\pgfmathparse{\pgfdecorationgrowthendstep * \pgfdecoratedpathlength}
|
|
\ifdim\pgfdecoratedcompleteddistance>\pgfmathresult pt%
|
|
\foreach \endsize [count=\count] in \pgfdecorationgrowthendsizelist {%
|
|
\ifnum\count=\pgfdecorationliststeps%
|
|
\global\edef\pgfdecorationgrowthendsize{\endsize}%
|
|
\breakforeach%
|
|
\else%
|
|
\global\edef\pgfdecorationgrowthstart{\endsize}%
|
|
\fi%
|
|
}%
|
|
\global\edef\tempa{0}%
|
|
\foreach \growthstep [count=\count] in \pgfdecorationgrowthendstepslist {%
|
|
\ifnum\count=\pgfdecorationliststeps%
|
|
\global\edef\pgfdecorationgrowthendstep{\growthstep}%
|
|
\breakforeach%
|
|
\else%
|
|
\global\edef\tempa{\growthstep}%
|
|
\fi%
|
|
}%
|
|
\foreach \wavelength [count=\count] in \pgfdecorationgrowthwavelengthlist {%
|
|
\ifnum\count=\pgfdecorationliststeps%
|
|
\global\edef\pgfdecorationgrowthwavelength{\wavelength}%
|
|
\breakforeach%
|
|
\fi%
|
|
}%
|
|
\pgfmathparse{int(\pgfdecorationliststeps+1)}%
|
|
\global\edef\pgfdecorationliststeps{\pgfmathresult}%
|
|
\global\edef\pgfdecorationgrowthsteps{0}% Redefine the steps counter, globally.
|
|
\pgfmathparse{(\pgfdecorationgrowthendsize-\pgfdecorationgrowthstart) * 2 %
|
|
* \pgfdecorationgrowthwavelength / (\pgfdecoratedpathlength * (\pgfdecorationgrowthendstep -\tempa))}%
|
|
\global\edef\pgfdecorationgrowth{\pgfmathresult}%
|
|
\fi%
|
|
}
|