我使用了以下代码来回答这个问题,(使用循环方法)绘制同心图形。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Spiro using loop}%rounded corners solution 1
\vskip -.6cm
\begin{tikzpicture}
\begin{scope}[scale=2]%transparency group,opacity=.4,
\draw[line width=.2cm,blue!80!black, fill=blue, looseness=1]
(0,-2.2) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-2.2) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (1.9,1.9) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue, fill=blue!80!white, looseness=1]
(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;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!80!white, fill=blue!70!white, looseness=1]
(0,-1.8) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-1.8) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (1.5,1.5) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!70!white, fill=blue!60!white, looseness=1]
(0,-1.6) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-1.6) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (1.3,1.3) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!60!white, fill=blue!50!white, looseness=1]
(0,-1.4) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-1.4) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (1.1,1.1) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!50!white, fill=blue!40!white, looseness=1]
(0,-1.2) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-1.2) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (.9,.9) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!40!white, fill=blue!30!white, looseness=1]
(0,-1.) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-1.) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (.7,.7) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!30!white, fill=blue!20!white, looseness=1]
(0,-.8) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-.8) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (.5,.5) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!20!white, fill=blue!10!white, looseness=1]
(0,-.6) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-.6) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (.3,.3) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\begin{scope}[scale=2]
\draw[line width=.2cm,blue!10!white, fill=blue!0!white, looseness=1]
(0,-.4) foreach \X in {0,90,180,270}
{[rotate=\X] -- (0,-.4) to [out=0,in=-120] ++ (0.2,0.1) to [out=60,in=-150] ++ (.1,.1) to [out=30,in=-90] ++ (0.1,0.2)} -- cycle;
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
如何简化此代码。
答案1
您也可以通过缩放来实现此效果。它与您的图片并不完全匹配,但这是故意的,因为我认为有效角的弧线也需要缩放。
\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}
答案2
找到模式并使用嵌套循环。
\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}