11

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.

14

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}

Output

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.