2

I used the following code from the answer to this question

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{spirob/.style={insert path={(0,0) foreach \X in {0,90,180,270}
{[rotate=\X] (0,0) to [out=90,in=-180] ++ (2.5,2.5)} -- cycle
}}}
\begin{document}
\begin{frame}[t]
\frametitle{Spirograph 2}
\begin{tikzpicture}
\begin{scope}
 \foreach \Y [count=\Z starting from 0] in {red,blue,green,red,blue,green,red,blue,green} {\draw[fill=none,rotate=\Z*10,spirob,fill opacity=0.3]; }
 \foreach \Y in {0,1,2,3,4,5,6,7,8} 
{
 \begin{scope}
 \foreach \Z in {0,1,2,3,4,5,6,7,8} {\ifnum\Y=\Z \else \path[clip,rotate=\Z*10,spirob]; \fi};
 \end{scope}
}
 \foreach \Y [count=\Z starting from 0] in {red,blue,green,red,blue,green,red,blue,green} {\draw[draw=\Y,fill=\Y!40,line width=0.5mm,rotate=\Z*10,spirob]; } 
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

How to make the first red/blue loops overlap the last green one as in the following drawing

enter image description here

Hany
  • 4,709

1 Answers1

4

Since these are the same shapes with just alternating colors and rotations, I'd use only one loop. At some point you can then add a clip that protects the earlier drawings from getting overpainted. I took \Z=30 but 30 is not special in that regard.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{spirob/.style={insert path={
(0,0) to [out=90,in=-180] ++ (2.5,2.5)} -- cycle}}
\begin{document}
\begin{frame}[t]
\frametitle{Spirograph 2}
\begin{tikzpicture}
\begin{scope}
  \def\lstColors{"red","blue","green"}
  \foreach \Z in {0,...,35}
  {\pgfmathsetmacro{\Y}{{\lstColors}[Mod(\Z,3)]}
  \draw[draw=\Y,fill=\Y!40,line width=0.5mm,rotate=\Z*10,spirob];
  \ifnum\Z=30
    \clip[overlay] (-45:0.25mm) -- ++ (45:4) arc(45:-45:4) -- cycle;
  \fi}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here