Is it possible to change the phase of the snake
decoration? I want it to start, e.g. at the maximum of a wiggle. I find the option phase
only for dashes.
1 Answer
You could create your own Snake
decoration that starts at the “maximum of a wiggle”.
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\pgfdeclaredecoration{Snake}{initial}
{
\state{initial}[switch if less than=+.625\pgfdecorationsegmentlength to final,
width=+.3125\pgfdecorationsegmentlength,
next state=down]{
\pgfpathmoveto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
}
\state{down}[switch if less than=+.8125\pgfdecorationsegmentlength to end down,
width=+.5\pgfdecorationsegmentlength,
next state=up]{
\pgfpathcosine{\pgfqpoint{.25\pgfdecorationsegmentlength}{-1\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfqpoint{.25\pgfdecorationsegmentlength}{-1\pgfdecorationsegmentamplitude}}
}
\state{up}[switch if less than=+.8125\pgfdecorationsegmentlength to end up,
width=+.5\pgfdecorationsegmentlength,
next state=down]{
\pgfpathcosine{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
}
\state{end down}[width=+.3125\pgfdecorationsegmentlength,
next state=final]{
\pgfpathcosine{\pgfqpoint{.15625\pgfdecorationsegmentlength}{-.5\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfqpoint{.15625\pgfdecorationsegmentlength}{-.5\pgfdecorationsegmentamplitude}}
}
\state{end up}[width=+.3125\pgfdecorationsegmentlength,
next state=final]{
\pgfpathcosine{\pgfqpoint{.15625\pgfdecorationsegmentlength}{.5\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfqpoint{.15625\pgfdecorationsegmentlength}{.5\pgfdecorationsegmentamplitude}}
}
\state{final}{\pgfpathlineto{\pgfpointdecoratedpathlast}}
}
\begin{document}
\begin{tikzpicture}[decoration={snake}]
\draw[->,decorate] (0, 5mm) -- ++(4,0);
\draw[->,decorate] (0,0) -- ++(3,0);
\draw[->,decorate] (0,-5mm) -- ++(2,0);
\draw[->,decorate] (0,-1cm) -- ++(1,0);
\end{tikzpicture}
\begin{tikzpicture}[decoration={Snake}]
\draw[->,decorate] (0, 5mm) -- ++(4,0);
\draw[->,decorate] (0,0) -- ++(3,0);
\draw[->,decorate] (0,-5mm) -- ++(2,0);
\draw[->,decorate] (0,-1cm) -- ++(1,0);
\end{tikzpicture}
\end{document}