7

To get more control on Spirograph patterns, the Spirograph code from the answer to this question, needs to be modified.

This code is

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usetikzlibrary{shadings}
\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}[fragile,t]
\frametitle{Spiro 1 orig}
\begin{tikzpicture}[]
 \draw
 (0,0) pic[scale=0.5, violet, line width=0.6mm, rotate=45, lower left=orange, lower right=yellow, upper left=red, upper right=magenta]{spiro}
;
\end{tikzpicture}
\end{frame}
\end{document}

Which produces enter image description here

Here is what is in my mind. I need to draw the pattern in segments, and define the location of the starting point.

The distance point P has to travel, to complete a cycle (360 degrees), is expressed as 2*pi. So, to draw 0.25 of the curve, 0.5 of the curve, or the whole curve; you need to say (2*pi*0.25), (2*pi*0.5), or (2*pi*1), respectively. enter image description here

It might take more than one cycle to complete the whole pattern. To draw the figure to the left, it takes 2 nRotations. The first draws the red one, the second draws the blue one, to get the figure to the right. enter image description here

In the original code

t = vectorin(0, 0.05, 2*pi*nRotations)

where (0, 0.05, 2*pi) tells the programme to draw the curve in small lines, in increments of 5 percent (0.05) starting from point 0 to point 2*pi. The 0.05 increments determine the smoothness of the curve, especially for more complicated patterns.

For example using

t = vectorin(0, 0.05, 2 * pi * v_nRotations)

produces enter image description here

while using

t = vectorin(0, 0.005, 2 * pi * v_nRotations) produces a smoother curve enter image description here

To draw a pattern in segments, we must control the rotation of point P

This is needed to make the one-colour left figure looks like the multiple-colour right one. enter image description here

The original code

spirograph = function (R, r, p, nRotations, color)
t = vectorin(0, 0.05, 2*pi*nRotations)
spirograph(60, -15, 10,  1, green)

is modified to draw the pattern in 4 separate segments, each with a different colour. Point P also starts not from point 2*pi*0, but from point 2*pi*(0.000-.125) (to make each peak of one colour) and going in steps of 2*pi*(0.125)*2 (by multiplying in a factor) to reach point 2*pi*(0.125)*7 (to complete the 360 degrees cycle).

The idea is to begin the first segment not from position 0, but half way before it; and to end it half way after it.

Starting from location 0, produces a less attractive pattern. enter image description here

The new code becomes

spirograph = function (R, r, p, start, step, stop, object, lineSize, color, scale, n, fill)

t=vectorin(start, step, stop) (which provides more control on the beginning, increment, and end of the rotation cycle than when using nRotations)

addplot(object, x*scale, y* scale, n, lineSize, color, 0, 0, fill) (x*scale, y* scale is used in other drawings to control the x and y scaling separately)

The following code: (which P starts from point 2*pi*0.0 to 2*pi*1.0) draws the pattern in Green

spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*0.00 , 0.05, 2*pi*1.00, p, 6, Green, 3.5, 0*360/4/6, "Transparent")
showplot(p, 0, 1, 1)

enter image description here

using the following code: which P starts from point 2*pi*(0.000-.125) to 2*pi*(0.000+.125) and then rotating the resulting peak

spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125), p, 6, Green,  3.5, 0*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125), p, 6, Blue ,  3.5, 1*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125), p, 6, Red  ,  3.5, 2*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125), p, 6, Violet, 3.5, 3*360/4, "Transparent")
showplot(p, 0, 1, 1)

or using the following code (begin from point 2*pi*(0.125)*-1 and rotated by multiplying in a factor)

spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.125)*-1 , 0.05, 2*pi*(0.125)*1, p, 6, Green , 3.5, 0*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.125)*1  , 0.05, 2*pi*(0.125)*3, p, 6, Blue  , 3.5, 0*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.125)*3  , 0.05, 2*pi*(0.125)*5, p, 6, Red   , 3.5, 0*360/4, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.125)*5  , 0.05, 2*pi*(0.125)*7, p, 6, Violet, 3.5, 0*360/4, "Transparent")
showplot(p, 0, 1, 1)

produce the left drawing in enter image description here

This routine can be repeated and rotated to draw the right drawing, with filling

enter image description here

spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 0*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 0*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 0*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 0*360/4/6, "#55ff00ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 1*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 1*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 1*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 1*360/4/6, "#55ff00ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 2*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 2*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 2*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 2*360/4/6, "#55ff00ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 3*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 3*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 3*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 3*360/4/6, "#55ff00ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 4*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 4*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 4*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 4*360/4/6, "#55ff00ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.125) , 0.05, 2*pi*(0.000+.125),     p, 6, Green, 3.5, 5*360/4/6, "#5500ff00")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*1-.125) , 0.05, 2*pi*(0.250*1+.125), p, 6, Blue,  3.5, 5*360/4/6, "#550000ff")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*2-.125) , 0.05, 2*pi*(0.250*2+.125), p, 6, Red,   3.5, 5*360/4/6, "#55ff0000")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250*3-.125) , 0.05, 2*pi*(0.250*3+.125), p, 6, Violet,3.5, 5*360/4/6, "#55ff00ff")
showplot(p, 0, 1, 1)

Instead of drawing a whole pattern in segments, only a part of the pattern can be drawn, repeated, rotated, filled and scaled to produce more appealing drawings. Some experiments are needed to find out where the used parts meet each other, to avoid their overlapping. enter image description here

spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#0000AA", 3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#0000AA", 3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#0000AA", 3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#0000AA", 3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#AA0000",  3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#AA0000",  3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#AA0000",  3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#AA0000",  3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#FFDD00", 3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#FFDD00", 3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#FFDD00", 3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.5 , -15*1.5 , 12*1.5 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#FFDD00", 3.0, 7*(360/4/8)+0, "Transparent")
"showplot(p, 0, 1, 1)"
 --------------------------------------------------------------------------------------------------------- 
"p = createplot()"
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#008800",   3.0, 0*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#0000AA",   3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#0000AA",   3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#0000AA",   3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#0000AA",   3.0, 1*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#9933CC",   3.0, 2*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#AA0000",   3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#AA0000",   3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#AA0000",   3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#AA0000",   3.0, 3*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#D2691E",   3.0, 4*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#E9967A",   3.0, 5*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#DAA520",   3.0, 6*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.000-.055), 0.05, 2*pi*(0.000+.055), p, 2, "#FFDD00",   3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.250-.055), 0.05, 2*pi*(0.250+.055), p, 2, "#FFDD00",   3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.500-.055), 0.05, 2*pi*(0.500+.055), p, 2, "#FFDD00",   3.0, 7*(360/4/8)+0, "Transparent")
spirograph(60*1.25 , -15*1.25 , 12*1.25 , 2*pi*(0.750-.055), 0.05, 2*pi*(0.750+.055), p, 2, "#FFDD00",   3.0, 7*(360/4/8)+0, "Transparent")
"showplot(p, 0, 1, 1)"
---------------------------------------------------------------------------------------------------------
and so on

Another method is to draw the needed parts in colour, and the unneeded parts in white or transparent. enter image description here

spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 0*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 0*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 0*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 0*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 0*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 0*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 0*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 0*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 1*360/4/8,"#FF7CFC00")
pirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 1*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 1*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 1*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 1*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 1*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 1*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 1*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 2*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 2*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 2*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 2*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 2*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 2*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 2*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 2*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 3*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 3*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 3*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 3*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 3*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 3*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 3*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 3*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 4*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 4*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 4*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 4*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 4*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 4*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 4*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 4*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 5*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 5*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 5*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 5*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 5*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 5*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 5*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 5*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 6*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 6*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 6*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 6*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 6*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 6*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 6*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 6*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250-.045) , 0.05, 2*pi*(.250+.045), p, 2, Green,  3.0, 7*360/4/8,"#FF7CFC00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.250+.045) , 0.05, 2*pi*(.500-.045), p, 2, Transparent,  3.0, 7*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500-.045) , 0.05, 2*pi*(.500+.045), p, 2, Blue,   3.0, 7*360/4/8,"#AA0000FF")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.500+.045) , 0.05, 2*pi*(.750-.045), p, 2, Transparent,  3.0, 7*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750-.045) , 0.05, 2*pi*(.750+.045), p, 2, Red,    3.0, 7*360/4/8,"#AAFF0000")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(.750+.045) , 0.05, 2*pi*(1.000-.045), p, 2, Transparent, 3.0, 7*360/4/8,"Transparent")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000-.045) , 0.05, 2*pi*(1.000+.045), p, 2, Violet, 3.0, 7*360/4/8,"#AAFF8C00")
spirograph(60*1.5 , -15*1.5 , 10*1.5 , 2*pi*(1.000+.045) , 0.05, 2*pi*(1.250-.045), p, 2, Transparent, 3.0, 7*360/4/8,"Transparent")
showplot(p, 0, 1, 1)
4
  • So... what is the question? And how is this related to TikZ in particular, or LaTeX in general?
    – fractal
    Dec 29, 2019 at 14:00
  • @Fractal I would like to edit the code from my previous question to allow controlling drawing the pattern in segments, and define the location of the starting point, as mentioned in this question examples.
    – Hany
    Dec 29, 2019 at 14:58
  • (tex.stackexchange.com/q/521684) Yes, but that is another question.
    – fractal
    Dec 29, 2019 at 15:00
  • @ Fractal I edited my question to include the code I need to modify.
    – Hany
    Dec 29, 2019 at 16:10

1 Answer 1

6

It is very easy to add some features like a domain and a dx to the older version of the spiro pic. I just focus on two of your screen shots for illustration, but think you can do all of them with the adjusted syntax. Please let me know if I am missing something.

\documentclass[tikz,border=3mm]{standalone}
\tikzset{pics/spiro2/.style={code={
\tikzset{spiro2/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro2/##1}} 
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spiro2/samples=\pgfmathresult}
\draw[trig format=rad,pic actions] 
 plot[variable=\t,domain=\pv{xmin}-0.002:\pv{xmax}+0.002,
    samples=\pv{samples}] 
    ({(\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})});
    }},
spiro2/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,
dx/.initial=0.005,samples/.initial=21,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spiro2/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spiro2/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi}
\begin{document}
\begin{tikzpicture}[]
 \draw 
   (0,0) foreach \X [count=\Y starting from 0] in {blue,red,purple,orange}
   {pic[scale=0.5,draw=\X,ultra
   thick]{spiro2={domain={-pi/4+(\Y-1)*pi/2}:{-pi/4+\Y*pi/2}}}};
 \draw(0,-7) foreach \X [count=\Y starting from 0] in {blue,red,purple,orange}
   {foreach \Z in {0,...,5}
   {pic[scale=0.5,draw=\X,ultra thick,fill=\X,fill
   opacity=0.2,rotate=\Z*15]{spiro2={domain={-pi/4+(\Y-1)*pi/2}:{-pi/4+\Y*pi/2}}}}};  
\end{tikzpicture}
\end{document}

enter image description here

Please note that the older version used smooth cycle so one could get good results with a comparatively small number of samples. Here, on the other hand, I followed your instructions to connect the plot points by straight lines, so one needs more samples and longer time to compile. Please let me know if one should go back to the smooth case to increase the speed. Doing that yields

\documentclass[tikz,border=3mm]{standalone}
\tikzset{pics/spiro2/.style={code={
\tikzset{spiro2/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro2/##1}} 
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spiro2/samples=\pgfmathresult}
\draw[trig format=rad,pic actions] 
 plot[variable=\t,domain=\pv{xmin}-0.002:\pv{xmax}+0.002,
    samples=\pv{samples},smooth] 
    ({(\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})});
    }},
spiro2/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,
dx/.initial=0.05,samples/.initial=21,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spiro2/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spiro2/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi}
\begin{document}
\begin{tikzpicture}
 \draw 
   (0,0) foreach \X [count=\Y starting from 0] in {blue,red,purple,orange}
   {pic[scale=0.5,draw=\X,ultra
   thick]{spiro2={domain={-pi/4+(\Y-1)*pi/2}:{-pi/4+\Y*pi/2}}}};
 \draw(0,-7) foreach \X [count=\Y starting from 0] in {blue,red,purple,orange}
   {foreach \Z in {0,...,5}
   {pic[scale=0.5,draw=\X,ultra thick,fill=\X,fill
   opacity=0.2,rotate=\Z*15]{spiro2={domain={-pi/4+(\Y-1)*pi/2}:{-pi/4+\Y*pi/2}}}}};  
\end{tikzpicture}
\end{document}

enter image description here

It appears natural to me to combine this with path fading.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings,fadings}
\tikzset{pics/spiro2/.style={code={
\tikzset{spiro2/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro2/##1}} 
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spiro2/samples=\pgfmathresult}
\draw[trig format=rad,pic actions] 
 plot[variable=\t,domain=\pv{xmin}-0.002:\pv{xmax}+0.002,
    samples=\pv{samples},smooth] 
    ({(\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})});
    }},
spiro2/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,
dx/.initial=0.05,samples/.initial=21,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spiro2/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spiro2/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi}
\begin{document}
\begin{tikzfadingfrompicture}[name=spiro]
\draw foreach \Y in {0,...,3}
   {foreach \Z in {0,...,5}
   {pic[scale=0.5,fill=transparent!60,
   draw=transparent!20,
   rotate=\Z*15]{spiro2={domain={-pi/4+(\Y-1)*pi/2}:{-pi/2+pi/9+\Y*pi/2}}}}};  
\end{tikzfadingfrompicture}
\begin{tikzpicture}
 \shade[shading=color wheel,
  path fading=spiro,fit fading=false] (0,0) circle [radius=4cm];
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: These are the requested graphs. I added some explanations to the code. Explaining something well requires the knowledge where the other user involved is struggling. I do not have this knowledge. If you ask specific questions, I will try to answer them.

\documentclass[tikz,border=3mm]{standalone}
% The following just sets up a plot where you can contol the parameters via pgf
% keys. The central object is the plot.
\tikzset{pics/spiro2/.style={code={
\tikzset{spiro2/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro2/##1}} 
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spiro2/samples=\pgfmathresult}
\draw[trig format=rad,pic actions] 
 plot[variable=\t,domain=\pv{xmin}-0.002:\pv{xmax}+0.002,
    samples=\pv{samples},smooth] 
    ({(\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})});
    }},
spiro2/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,
dx/.initial=0.08,samples/.initial=21,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spiro2/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spiro2/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi}
\begin{document}
\begin{tikzpicture}
 \path (0,0)  
  pic[scale=0.5,draw=yellow,ultra   thick]{spiro2={dx=0.03}}
   foreach \X [count=\Y starting from 0] in {blue,red,purple,orange}
   {pic[scale=0.5,draw=\X,ultra
   thick]{spiro2={domain={-pi/12+\Y*pi/2}:{pi/12+\Y*pi/2}}}};
 % This is a loop orgy. We loop over scale factors, overall rotations and colors.   
 \path[line cap=round] (7,0)  
   foreach \ScaleN 
    [evaluate=\ScaleN as \Scale using {pow(0.85,\ScaleN)/0.8}] % compute sale factor
    in {1,...,5} %loop over scale
     {foreach \Z in {0,...,3} %loop over 4 overall rotations
       {foreach \X [count=\Y starting from 0] in 
         {yellow,orange,red,blue,purple,cyan,magenta,green!70!black} % colors
       {pic[scale=0.5,draw=\X,rotate=\Y*90/8+\Z*90,
       scale=\Scale,line width=\Scale*2pt]
       {spiro2={domain={-pi/11.4}:{pi/11.4}}}}}};
\end{tikzpicture}
\end{document}

enter image description here

13
  • Thank you very much. I will check your code, and I will get back to you.
    – Hany
    Dec 29, 2019 at 16:22
  • Thank you very much for your answer. I am not good in programming. If I may bother you please, I will appreciate it very much if you have time to explain to me your code. Or can you apply your code for these 2 figures so I can try to understand and figure out how to modify your code to get what is in my mind i.stack.imgur.com/GK1iu.png i.stack.imgur.com/QHLpn.png
    – Hany
    Dec 31, 2019 at 5:19
  • As you said, using more samples .005 makes compiling very slow. So using samples .05 with smooth is better. Using samples .005 can be used only for complicated figures which need this large samples
    – Hany
    Dec 31, 2019 at 5:26
  • 1
    @Hany I added these graphs along with some explanations.
    – user194703
    Dec 31, 2019 at 5:55
  • Thank you very much. I appreciate your efforts very much. I will study them. I hope I can understand your coding.
    – Hany
    Dec 31, 2019 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .