我使用了以下代码来回答这个问题
\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}
如何使第一个红色/蓝色循环与最后一个绿色循环重叠,如下图所示
答案1
由于这些是相同的形状,只是颜色和旋转交替,所以我只使用一个循环。在某个时候,你可以添加一个剪辑,以防止之前的绘图被覆盖。我拿了\Z=30
30 个,但在这方面并不特别。
\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}