Simplifying multiple \foreach loops

Find the pattern, and use nested loops.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Spiro using loop}
\vskip -.6cm
\begin{tikzpicture}
  \foreach \i in {0,.2,.4,...,1.8} {
    \pgfmathsetmacro\firstcolor{scalar(100-\i*50)}
    \pgfmathsetmacro\secondcolor{scalar(90-\i*50)}
    \begin{scope}[scale=2]
      \draw [
        line width=.2cm,color/.expanded=blue!\firstcolor!white,
        fill/.expanded=blue!\secondcolor!white, looseness=1
      ] (0,-2.2+\i) foreach \X in {0,90,180,270} {
        [rotate=\X] -- (0,-2.2+\i) to [out=0,in=-120] ++ (0.2,0.1) to 
        [out=60,in=-150] ++ (1.9-\i,1.9-\i) to [out=30,in=-90] ++ (0.1,0.2)
      } -- cycle;
    \end{scope}
  }
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here


You can get this effect also with scale. It does not match your picture precisely, but that's on purpose because I think the arcs of the effective corners are also to be scaled.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Spirifankerln}
\begin{tikzpicture}[pics/spiro/.style={code={
 \draw[line width=.1cm,looseness=1,pic actions]
  (0,-2) foreach \X in {0,90,180,270}
  {[rotate=\X] -- (0,-2) to[out=0,in=-120] ++ (0.2,0.1) to[out=60,in=-150] ++ (1.7,1.7)
  to[out=30,in=-90] ++ (0.1,0.2)} -- cycle;}}]
\foreach \X in {100,90,...,0}
{\pic[draw=blue!\X,fill=blue!\X,scale={1.8*(\X+10)/100}]{spiro};}
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Tags:

Tikz Pgf