13

I am trying to plot a football following the parabola

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

Which supposedly looks like this

enter image description here

Combining the football from tikzducks with blured or faded lines I was able to come up with the following.

  • Does there exists a cleaner / better approach?
  • How can the green grass at the bottom be approximated? (no exact solution needed).

enter image description here

\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}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

1 Answers1

14

How about adding some grass? ;-) shadows.blur allows you to draw the blurry frame. Another simplification can be achieved by making the soccer ball a pic whose center is at local coordinates (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}

enter image description here

And the mandatory animation can't be missing.

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

enter image description here

Or an attempt to slightly modify Paul Gaborit's stellar laser beam. (Well, for sure it is a modification, what is less clear is if it is an improvement.;-)

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

enter image description here

  • Amazing, and so quick! Any idea why the parabola is above the grass and not behind? Regards. – N3buchadnezzar Jun 10 '19 at 23:32
  • @N3buchadnezzar I changed the code a bit but I do not understand your comment. The grass is in front of the parabola. If you want the parabola in front of the grass, change the order of drawing. –  Jun 10 '19 at 23:44
  • Ah, I see. It just appears like the parabola is in front of the grass because of the random function. Much appreciated =) – N3buchadnezzar Jun 10 '19 at 23:53