tikz 蛇形装饰阶段

tikz 蛇形装饰阶段

是否可以更改装饰的阶段snake?我希望它从摆动的最大值开始。我发现phase只有破折号才有选项。

答案1

您可以创建自己的Snake装饰,从“最大摆动”开始。

代码

\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}

输出

在此处输入图片描述

相关内容