3

I used the following code, from the answer to this question

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Spirograph 1--}
\begin{tikzpicture}[pics/fcross/.style={code={
\path[fill=blue!40!white, looseness=1,pic actions] 
(0,0) node {x} (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;
}}]
 \begin{scope}[blend group=lighten,fill opacity=.4]
  \path foreach \Y in {0,30,60} {pic[rotate=\Y,scale=2,line width=.2cm,draw=blue] {fcross}};
 \end{scope} 
\end{tikzpicture}
\end{frame}
\begin{frame}[t]
\frametitle{Spirograph 1}
\begin{tikzpicture}[pics/fcross/.style={code={
\path[line width=.1cm,fill=blue!40!white, 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;
}}]
 \begin{scope}[blend group=lighten,fill opacity=.4]
  \path foreach \Y in {0,30,60} {pic[rotate=\Y,scale=2] {fcross}};
 \end{scope} 
 \path foreach \Y in {0,30,60} {pic[rotate=\Y,scale=2,fill=none,draw=blue!40] {fcross}};
\end{tikzpicture}
\end{frame}
\end{document}

How can I make the colour of the filling of the repeated drawings gradient, or produce the following drawings

enter image description here

enter image description here

Hany
  • 4,709
  • 1
    You can try to add a second counter which covers the desidered colors, i.e.: "\foreach \color [count=\Y] in {blue,cyan,purple}...." modifying "pic[rotate=(\Y-1)*30,scale=2,fill=none,draw=\color]" – Colo Dec 18 '19 at 14:53
  • @Colo Would you please tell me the full code to apply. – Hany Dec 18 '19 at 16:31
  • Schrödinger's cat's answer shows what I meant... – Colo Dec 18 '19 at 20:39

2 Answers2

3

The previous questions of yours in this context could be answered using an appropriate blend group. Here I think this is no longer the case. Rather, one can use clip. And the different colors can be built in the loop, as mentioned by Colo. Here are examples. The whole story now comes a bit reminiscent of the experimental venndiagrams library, but of course clip has been used all over.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{contour/.style={insert path={(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
}}}
\begin{document}
\begin{frame}[t]
\frametitle{Spirograph 1}
\begin{tikzpicture}
\begin{scope}[local bounding box=L]
  \foreach \Y [count=\Z starting from 0]
  in {red,blue,blue!50} 
  {\draw[fill=\Y,rotate=\Z*30,contour,fill opacity=0.5]; }
  \foreach \Y in {0,1,2}
  {\begin{scope}
   \foreach \Z  in {0,1,2}
   {\ifnum\Y=\Z
   \else
    \path[clip,rotate=\Z*30,contour];
   \fi}
   \fill[yellow] (L.south west) rectangle (L.north east);
  \end{scope}}
  \foreach \Z  in {0,1,2}
  {\draw[draw=blue!40,line width=0.5mm,rotate=\Z*30,contour]; }
\end{scope}  
\begin{scope}[local bounding box=R,xshift=5cm]
  \foreach \Y [count=\Z starting from 0]
  in {red,blue,blue!50} 
  {\draw[fill=\Y,draw=blue!40,line width=0.5mm,rotate=\Z*30,contour,fill opacity=0.5]; }
  \foreach \Y in {0,1,2}
  {\begin{scope}
   \foreach \Z  in {0,1,2}
   {\ifnum\Y=\Z
   \else
    \path[clip,rotate=\Z*30,contour];
   \fi}
   \fill[cyan!40] (R.south west) rectangle (R.north east);
  \end{scope}}
\end{scope}  
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

  • Thank you very much for your answer. Just one more comment, in the right diagram, instead of {\draw[fill=\Y,draw=blue!40,line width=0.5mm,rotate=\Z30,contour,fill opacity=0.5]; }, I used {\draw[fill=\Y,draw=\Y,line width=0.5mm,rotate=\Z30,contour,fill opacity=0.5]; }. How can this be applied in the left diagram to make outline colour as fill colour. – Hany Dec 19 '19 at 05:39
  • 1
    @Hany Sorry, I do not understand. Do you mean \begin{scope}[local bounding box=L] \foreach \Y [count=\Z starting from 0] in {red,blue,blue!50} {\draw[fill=\Y,rotate=\Z*30,contour,fill opacity=0.5]; } \foreach \Y in {0,1,2} {\begin{scope} \foreach \Z in {0,1,2} {\ifnum\Y=\Z \else \path[clip,rotate=\Z*30,contour]; \fi} \fill[yellow] (L.south west) rectangle (L.north east); \end{scope}} \foreach [count=\Z starting from 0] \Y in {red,blue,blue!50} {\draw[draw=\Y,line width=0.5mm,rotate=\Z*30,contour]; } \end{scope}? –  Dec 19 '19 at 05:57
  • Yes. Thank you. – Hany Dec 19 '19 at 06:08
3

A metapost solution. Rounded corners were the biggest issue. enter image description here

\documentclass{article}
\usepackage{luamplib}
\begin{document}
\mplibnumbersystem{double}
\mplibforcehmode
\begin{mplibcode}
u:=1cm; r:=.2cm;
path p[]; pen mypen; color c[];
c1=.7[red,white];
c2=.7[blue,white];
c3=.4[red,white];
c4=(.99,.93,0);
% envelope needs a polygonal pen, so approximate a circular pen
p[-1]:= (r,0) for i=1 upto 120: --(r,0) rotated 3i endfor--cycle;
mypen:= makepen(p[-1]);
pickup mypen;
% set coords so that outer edge of pen hits them, not center
rt z0=u*(2,0);
top z1=u*(0,2);
lft z2=u*(-2,0);
bot z3=u*(0,-2);
p0=z0{dir 150}..{dir 120}z1{dir 240}..{dir 210}z2{dir 330}..{dir 300}z3{dir 60}..{dir 30}z0..cycle;
% draw path with pen of radius=rounded corner radius, envelope=outer boundary of this path
p1=envelope mypen of p0;
% remainder is fairly self explanatory.
p2=p1 rotated 30;
p3=p2 rotated 30;
z4=p1 intersectiontimes p2;
z5=p1 intersectiontimes p3;
p4=subpath (xpart z4-eps,xpart z5+eps) of p1;
p5=subpath (ypart z5-eps,ypart z4+eps) of p3;
p6=subpath (ypart z4-eps,length p2+xpart z4+eps) of p2;
p7=buildcycle(p4,p5,p6);

beginfig(0);
for i=1 upto 3: fill p[i] withcolor c4; endfor;
for i=0 upto 3:
    for j=0 upto 3:
        fill p7 rotated (30i+90j) withcolor c[i];
    endfor;
endfor;
for i=1 upto 3: draw p[i] withcolor .5[blue,white]; endfor;
endfig;

beginfig(1);
for i=1 upto 3: fill p[i] withcolor .8[blue,white]; endfor;
for i=0 upto 3:
    for j=0 upto 3:
        fill p7 rotated (30i+90j) withcolor c[i];
        draw p7 rotated (30i+90j) withcolor .5[blue,white];
    endfor;
endfor;
endfig;
\end{mplibcode}
\end{document}
Scott H.
  • 11,047
  • Thank you for your answer. I am not familiar with LuaLatex. Would you please tell me where can I learn about it to understand your code. – Hany Dec 20 '19 at 04:44
  • 1
    @Hany lualatex is like regular latex but with built in lua and metapost compilers. The metapost manual is https://www.tug.org/docs/metapost/mpman.pdf and there are some good links at https://www.tug.org/metapost.html – Scott H. Dec 20 '19 at 21:42
  • Thank you for your links – Hany Dec 21 '19 at 04:29