足球沿着抛物线和草丛前进

足球沿着抛物线和草丛前进

我正在尝试绘制一个跟随抛物线的足球

f(x) = -0.1x^2 + 2x    ,     0 <= x <= 20

看起来像这样

在此处输入图片描述

合并来自 tikzducks 的足球线条模糊或褪色我能够想到以下方法。

  • 是否存在更清洁/更好的方法?
  • 底部的绿草如何近似?(不需要精确的解决方案)。

在此处输入图片描述

\documentclass[tikz,border=1mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{ifthen}

\tikzset{
  laser beam action/.style={
    line width=\pgflinewidth+.2pt,draw opacity=.1,draw=#1,
  },
  laser beam recurs/.code 2 args={%
    \pgfmathtruncatemacro{\level}{#1-1}%
    \ifthenelse{\equal{\level}{0}}%
    {\tikzset{preaction={laser beam action=#2}}}%
    {\tikzset{preaction={laser beam action=#2,laser beam recurs={\level}{#2}}}}
  },
  laser beam/.style={preaction={laser beam recurs={10}{#1}},draw opacity=1,draw=#1},
}


\begin{document}

  \begin{tikzpicture}[scale=0.5]
    \draw[black, dashed, ultra thick]   plot[smooth,domain=0:20] (\x,
    {-0.1*\x*\x+2*\x});
    \begin{scope}[scale=2,shift={(-0.6,0.75)}]
      \fill[gray!30!white] (1.2,0.33) circle (0.32);
      \clip (1.2,0.33) circle (0.32);
      \fill[black] (1.06,0.30) -- (1.01,0.17) -- (1.14,0.08) -- (1.26,0.14) -- (1.20,0.28) -- cycle (1.37,0.14) -- (1.46,0.27) -- (1.59,0.27) -- (1.41,0.04) -- cycle (1.28,0.38) -- (1.22,0.52) -- (1.33,0.61) -- (1.45,0.51) -- (1.43,0.37) -- cycle (0.87,0.44) -- (1.02,0.40) -- (1.10,0.53) -- (1.07,0.62) -- (0.94,0.57) -- cycle;
    \end{scope}
    \path[rounded corners=1mm,ultra thick, laser beam=black!40,line width=2pt] (-0.25,-0.25) -- (20.25,-0.25) -- (20.25,12.25) --
    (-0.25,12.25) -- cycle;
  \end{tikzpicture}

\end{document}

答案1

添加一些草怎么样? ;-)shadows.blur允许您绘制模糊的框架。 通过将足球变成中心位于本地坐标的图片,可以实现另一个简化(0,0)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shadows.blur}

\begin{document}

  \begin{tikzpicture}[scale=0.5,pics/soccer ball/.style={code={
  \fill[gray!30!white] (0,0) circle (0.32);
      \clip (0,0) circle (0.32); 
      \fill[black] (-1.2+1.06,-0.33+0.30) -- (-1.2+1.01,-0.33+0.17) -- (-1.2+1.14,-0.33+0.08) -- (-1.2+1.26,-0.33+0.14) -- (-1.2+1.20,-0.33+0.28) -- cycle 
      (-1.2+1.37,-0.33+0.14) -- (-1.2+1.46,-0.33+0.27) -- (-1.2+1.59,-0.33+0.27) -- (-1.2+1.41,-0.33+0.04) -- cycle 
      (-1.2+1.28,-0.33+0.38) -- (-1.2+1.22,-0.33+0.52) -- (-1.2+1.33,-0.33+0.61) -- (-1.2+1.45,-0.33+0.51) -- (-1.2+1.43,-0.33+0.37) -- cycle 
      (-1.2+0.87,-0.33+0.44) -- (-1.2+1.02,-0.33+0.40) -- (-1.2+1.10,-0.33+0.53) -- (-1.2+1.07,-0.33+0.62) -- (-1.2+0.94,-0.33+0.57) -- cycle;}},
      declare function={pbl(\x)=-0.1*\x*\x+2*\x;}]
    \begin{scope}
    \clip (-1,-1) rectangle (10,13);
    \fill[white,rounded corners=1mm,blur shadow={shadow xshift=0pt,shadow yshift=0pt,shadow scale=1.04,
    shadow blur steps=10}] (-0.25,-0.25) rectangle (12.25,12.25) ;
    \end{scope}
    \begin{scope}
    \clip (10,-1) rectangle (21,13);
    \fill[white,rounded corners=1mm,blur shadow={shadow xshift=0pt,shadow yshift=0pt,shadow scale=1.04,
    shadow blur steps=10}] (7.75,-0.25) rectangle (20.25,12.25) ;
    \end{scope}
    \clip[rounded corners=1mm] (-0.25,-0.25) rectangle (20.25,12.25);
    \draw[black, dashed, ultra thick]   plot[smooth,domain=0:20] (\x,{pbl(\x)});
    \path (3,{pbl(3)}) pic{soccer ball};    
    \fill[green!70!black] plot[smooth,domain=-0.25:20.25,samples=501] (\x,0.2+0.3*rnd) |- (-0.25,-0.25);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

并且强制性动画不能缺失。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shadows.blur,decorations.markings}
\begin{document}
\foreach \X in {0.1,0.15,...,0.9}
{\begin{tikzpicture}[scale=0.5,pics/soccer ball/.style={code={
  \fill[gray!30!white] (0,0) circle (0.32);
      \clip (0,0) circle (0.32); 
      \fill[black] (-1.2+1.06,-0.33+0.30) -- (-1.2+1.01,-0.33+0.17) -- (-1.2+1.14,-0.33+0.08) -- (-1.2+1.26,-0.33+0.14) -- (-1.2+1.20,-0.33+0.28) -- cycle 
      (-1.2+1.37,-0.33+0.14) -- (-1.2+1.46,-0.33+0.27) -- (-1.2+1.59,-0.33+0.27) -- (-1.2+1.41,-0.33+0.04) -- cycle 
      (-1.2+1.28,-0.33+0.38) -- (-1.2+1.22,-0.33+0.52) -- (-1.2+1.33,-0.33+0.61) -- (-1.2+1.45,-0.33+0.51) -- (-1.2+1.43,-0.33+0.37) -- cycle 
      (-1.2+0.87,-0.33+0.44) -- (-1.2+1.02,-0.33+0.40) -- (-1.2+1.10,-0.33+0.53) -- (-1.2+1.07,-0.33+0.62) -- (-1.2+0.94,-0.33+0.57) -- cycle;}}]
    \begin{scope}
    \clip (-1,-1) rectangle (10,13);
    \fill[white,rounded corners=1mm,blur shadow={shadow xshift=0pt,shadow yshift=0pt,shadow scale=1.04,
    shadow blur steps=10}] (-0.25,-0.25) rectangle (12.25,12.25) ;
    \end{scope}
    \begin{scope}
    \clip (10,-1) rectangle (21,13);
    \fill[white,rounded corners=1mm,blur shadow={shadow xshift=0pt,shadow yshift=0pt,shadow scale=1.04,
    shadow blur steps=10}] (7.75,-0.25) rectangle (20.25,12.25) ;
    \end{scope}
    \clip[rounded corners=1mm] (-0.25,-0.25) rectangle (20.25,12.25);
    \draw[black, dashed, ultra thick,postaction={decorate,decoration={markings,mark=at position \X\space with {\pic{soccer ball};}}}]   plot[smooth,domain=0:20] (\x,{-0.1*\x*\x+2*\x});
    \fill[green!70!black] plot[smooth,domain=-0.25:20.25,samples=501] (\x,0.2+0.3*rnd) |- (-0.25,-0.25);

  \end{tikzpicture}}
\end{document}

在此处输入图片描述

或者尝试稍微修改保罗·加博里特的恒星激光束。(嗯,肯定是修改,但不太清楚的是是否是改进。;-)

\documentclass[tikz,border=3.14mm]{standalone}
\tikzset{laser beam action/.style={
    line width=\pgflinewidth+\pgfkeysvalueof{/tikz/laser/increment},
    draw opacity=\pgfkeysvalueof{/tikz/laser/opacity},
    draw=\pgfkeysvalueof{/tikz/laser/color},#1
  },
  laser beam recurs/.code 2 args={%
    \pgfmathtruncatemacro{\level}{#1-1}%
    \ifnum\level=0%
    \pgfkeysalso{/tikz/preaction={laser beam action=#2}}%
    \else%
    \pgfkeysalso{/tikz/preaction={laser beam action=#2,laser beam recurs={\level}{#2}}}
    \fi
  },
  laser beam/.style={preaction={laser beam recurs={\pgfkeysvalueof{/tikz/laser/iterations}}{#1}},draw opacity=1,draw=#1},
  blurry beam/.style 2 args={/utils/exec=\tikzset{laser/.cd,#2},
  preaction={laser beam recurs={\pgfkeysvalueof{/tikz/laser/iterations}}{#1}}},
  laser/.cd,increment/.initial=0.2pt,opacity/.initial=0.1,
  color/.initial=black,iterations/.initial=10
}
\begin{document}

  \begin{tikzpicture}[scale=0.5,pics/soccer ball/.style={code={
  \fill[gray!30!white] (0,0) circle (0.32);
      \clip (0,0) circle (0.32); 
      \fill[black] (-1.2+1.06,-0.33+0.30) -- (-1.2+1.01,-0.33+0.17) -- (-1.2+1.14,-0.33+0.08) -- (-1.2+1.26,-0.33+0.14) -- (-1.2+1.20,-0.33+0.28) -- cycle 
      (-1.2+1.37,-0.33+0.14) -- (-1.2+1.46,-0.33+0.27) -- (-1.2+1.59,-0.33+0.27) -- (-1.2+1.41,-0.33+0.04) -- cycle 
      (-1.2+1.28,-0.33+0.38) -- (-1.2+1.22,-0.33+0.52) -- (-1.2+1.33,-0.33+0.61) -- (-1.2+1.45,-0.33+0.51) -- (-1.2+1.43,-0.33+0.37) -- cycle 
      (-1.2+0.87,-0.33+0.44) -- (-1.2+1.02,-0.33+0.40) -- (-1.2+1.10,-0.33+0.53) -- (-1.2+1.07,-0.33+0.62) -- (-1.2+0.94,-0.33+0.57) -- cycle;}},
      declare function={pbl(\x)=-0.1*\x*\x+2*\x;}]
    \path[blurry beam={gray}{increment=0.1pt,iterations=51,opacity=0.02},rounded corners] (-0.25,-0.25) rectangle (20.25,12.25);  
    \clip[rounded corners=1mm] (-0.25cm+5pt,-0.25cm+5pt) rectangle
    (20.25cm-5pt,12.25cm-5pt);
    \draw[black, dashed, ultra thick]   plot[smooth,domain=0:20] (\x,{pbl(\x)});
    \path (3,{pbl(3)}) pic{soccer ball};    
    \fill[green!70!black] plot[smooth,domain=-0.25:20.25,samples=501] (\x,0.2+0.3*rnd) |- (-0.25,-0.25);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容