我使用了以下代码来回答这个问题将比例与颜色和旋转变化结合起来
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\tikzset{pics/spiro/.style={code={
\tikzset{spiro/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro/##1}}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=0:2*pi*\pv{nRotations}, samples=90*\pv{nRotations}+1, smooth cycle]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
);
}},
spiro/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,nRotations/.initial=1}
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`- - foreach}
\begin{center}
\vskip -.8cm
\begin{tikzpicture}[line width=.06cm]
\foreach \scl/\clr in {.8/10,.6/30,.4/50,.2/70}
{
(0,0) \pic[draw,blue,outer color=blue!80,inner color/.expanded=blue!\clr,scale=\scl]{spiro};
}
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`- foreach}
\begin{center}
\vskip -.8cm
\begin{tikzpicture}[line width=.06cm]
\foreach \scl/\clr/\clra in {.8/100/80,.7/80/70,.6/70/60,.5/60/50,.4/50/40,.3/40/30,.2/30/20,.1/20/10}
% \foreach \scl/\clr/\clra/\clrb in {.8/100/90/80,.7/90/80/70,.6/80/70/60,.5/70/60/50,.4/60/50/40,.3/50/40/30,.2/40/30/20,.1/30/20/10}
{
(0,0) \pic[draw/.expanded=blue!\clr,fill/.expanded=blue!\clra,scale=\scl]{spiro};
% (0,0) \pic[draw/.expanded=blue!\clr,outer color/.expanded=blue!\clra,inner color/.expanded=blue!\clrb,scale=\scl]{spiro};
}
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`- foreach}
\begin{center}
\vskip -.8cm
\begin{tikzpicture}[line width=.06cm]
\foreach \scl/\rotate/\clr/\clra in {.8/0/100/80,.7/10/80/70,.6/20/70/60,.5/30/60/50,.4/40/50/40,.3/50/40/30,.2/60/30/20,.1/70/20/10}
{
(0,0) \pic[draw/.expanded=blue!\clr,fill/.expanded=blue!\clra,scale=\scl,rotate/.expanded=\rotate]{spiro};
}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
但我不知道如何将它应用于以下代码:
通过旋转来改变绘制和填充颜色的比例
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`- - - -}
\begin{center}
\vskip -1.cm
\begin{tikzpicture}[line width=.8mm]
\draw
(0,0) pic[scale=.8, purple!80, rotate=0, fill=purple!60]{spiro}
(0,0) pic[scale=.7, red!80, rotate=10, fill=red!60]{spiro}
(0,0) pic[scale=.6, orange!80, rotate=20, fill=orange!60]{spiro}
(0,0) pic[scale=.5, yellow!80, rotate=30, fill=yellow!60]{spiro}
(0,0) pic[scale=.4, green!80, rotate=40, fill=green!60]{spiro}
(0,0) pic[scale=.3, cyan!80, rotate=50, fill=cyan!60]{spiro}
(0,0) pic[scale=.2, blue!80, rotate=60, fill=blue!60]{spiro}
(0,0) pic[scale=.1, violet!80, rotate=70, fill=violet!60]{spiro}
;
\end{tikzpicture}
\end{center}
\end{frame}
产生
答案1
您只需要循环颜色,就可以从计数器中得出比例和旋转角度。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{pics/spiro/.style={code={
\tikzset{spiro/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro/##1}}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=0:2*pi*\pv{nRotations}, samples=90*\pv{nRotations}+1, smooth cycle]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
);
}},
spiro/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,nRotations/.initial=1}
\begin{document}
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`- foreach}
\begin{center}
\vskip -1.cm
\begin{tikzpicture}[line width=.8mm]
\draw foreach \Col [count=\Y starting from 0]
in {purple,red,orange,yellow,green,cyan,blue,violet}
{pic[scale=.8-0.1*\Y, \Col!80, rotate=\Y*10, fill=\Col!60]{spiro}};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}