1

To draw different kinds of polygons, I use the following code modified from the answer to this post. The original code was designed to draw pentagons.

As noticed, when applying this modified code for drawing other polygons with different number of sides (triangle, tetragon, hexagon, octagon), a lot of work is needed to readjust the parameters concerning the relation between the number of the sides of the polygons and the angle between the sides, the scaling factor, the rotation angle of the polygons of each group (central polygon, and surrounding polygons), the spacing between the polygons and the spacing between the groups of polygons.

My questions are:

1- To facilitate editing the above parameters for drawing different types of polygons, I need to set each one of them as a separate variable that could be easily modified, without the need to do this manually in each case, as used in my modified code.

For example, I need to set the scaling variable and then apply it with the desired value in the needed location

setting a variable:

scl=scaled 0.381966

then instead of saying:

scaled 1.6424538 (which is 0.381966*4.3)

say:

scl*4.3

2- Is it possible to put those defined variables at the beginning of the document, instead of repeating them after every \begin{mplibcode}

3- Is it possible to define the colours to be used, instead of using the default colours

for example using something like this:

    \foreach \j/\rgb in
{0/violet, 1/red, 2/orange, 3/green!70!black, 4/cyan!70!black, 5/brown!70!black, 6/teal, 7/olive}{%
{pentagon={\rgb}{\rgb!30}};
}

4- How can I fix the spacing between the groups in the final compound figure

\documentclass[12pt,a4paper]{article}
\usepackage{luamplib}
\begin{document}
code2 coloured one drawing code tri1
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*1.62), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 180 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 120i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tri2
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 180 shifted (point i of p - point i of small_p*.6), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 0 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 120i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tri3
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 180 shifted (point i of p - point i of small_p*1.1), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 180 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 120i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tri4
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*1.1), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 0 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 120i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tetra1
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.9), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 45 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
code2 coloured one drawing code tetra2
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.6), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 0 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tetra3
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 45 shifted (point i of p - point i of small_p*1.2), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 45 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tetra4
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 45 shifted (point i of p - point i of small_p*.9), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tetra5
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 22.5 shifted (point i of p - point i of small_p*1.05), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 22.5 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code tetra6
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*1.6), 
if level=limit: Spectral[6][i] else: s fi);
endfor
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 90i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code penta1
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 180 shifted m,
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 72i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code penta2
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p scaled 1.145898 shifted (point i of p - point i of small_p*.75), %0.381966*2=1.145898
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 0.90907908 rotated 0 shifted m,% 0.381966*2.38=0.90907908
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 72i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code penta3
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 180 shifted (point i of p - point i of small_p*1.), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 0.6111456 rotated 0 shifted m,%0.381966*1.6=0.6111456
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 72i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code penta4
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 5:
flake(level -1, limit, small_p rotated 180 shifted (point i of p - point i of small_p*1.), 
if level=limit: Spectral[6][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 0.7257354 rotated 180 shifted m,%0.381966*1.9=0.7257354
if level=limit: Spectral 6 6 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 5:50 up rotated 72i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code hexa1
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 6:
flake(level -1, limit, small_p rotated 90 shifted (point i of p - point i of small_p*.89), 
if level=limit: Spectral[8][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 90 shifted m,%0.381966*3=1.145898
if level=limit: Spectral 8 8 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 6:50 up rotated 60i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code hexa2
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 6:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.6), 
if level=limit: Spectral[8][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 0 shifted m,
if level=limit: Spectral 8 8 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 6:50 up rotated 60i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code hexa3
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 6:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.6), 
if level=limit: Spectral[8][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.145898 rotated 90 shifted m,%0.381966*3=1.145898
if level=limit: Spectral 8 8 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 6:50 up rotated 60i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code hexa4
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 6:
flake(level -1, limit, small_p rotated 90 shifted (point i of p - point i of small_p*.58), 
if level=limit: Spectral[8][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.145898 rotated 0 shifted m,%0.381966*3=1.145898
if level=limit: Spectral 8 8 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 6:50 up rotated 60i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code octa1
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 8:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.2), 
if level=limit: Spectral[9][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 180 shifted m,
if level=limit: Spectral 9 9 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 8:50 up rotated 45i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code octa2
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 8:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.2), 
if level=limit: Spectral[9][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.3750776 rotated 0 shifted m,%0.381966*3.6=1.3750776
if level=limit: Spectral 9 9 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 8:50 up rotated 45i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code octa3
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 8:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.17), 
if level=limit: Spectral[9][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.527864 rotated 22.5 shifted m,%0.381966*4=1.527864
if level=limit: Spectral 9 9 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 8:50 up rotated 45i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code octa4
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 8:
flake(level -1, limit, small_p rotated 22.5 shifted (point i of p - point i of small_p/100), 
if level=limit: Spectral[9][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.7952402 rotated 22.5 shifted m,%0.381966*4.7=1.7952402    0.381966*4=1.527864
if level=limit: Spectral 9 9 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 8:50 up rotated 45i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
\vskip 1cm
code2 coloured one drawing code octa5
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 8:
flake(level -1, limit, small_p  rotated 22.5 shifted (point i of p - point i of small_p*.01), 
if level=limit: Spectral[9][i] else: s fi);
endfor
flake(level -1, limit, small_p scaled 1.6424538 rotated 0 shifted m,%0.381966*4.3=1.6424538  0.381966*4.4=1.6806504   0.381966*3.6=1.3750776
if level=limit: Spectral 9 9 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 8:50 up rotated 45i -- endfor cycle;
for j=1:
for i=1:
picture T; 
T=image(
flake(j, i, P, 0););
draw T;
 endfor
 endfor
 endfig;
\end{mplibcode}
%
=============
%
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef median(expr p)=origin for i=1 upto 6: + 1/6 point i of p
 endfor
 enddef;
vardef flake(expr level, limit, p, s)=
if level < 1:
fill p withcolor s;
draw p withcolor 3/4 s;
else:
save small_p, m;
path small_p; pair m; m=median(p); 
small_p=p shifted -m scaled 0.381966;
for i=1 upto 6:
flake(level -1, limit, small_p shifted (point i of p - point i of small_p*.6), 
if level=limit: Spectral[8][i] else: s fi);
endfor
flake(level -1, limit, small_p rotated 0 shifted m,
if level=limit: Spectral 8 8 else: s fi);
fi
enddef;
beginfig(1);
path P; P=for i=1 upto 6:50 up rotated 60i -- endfor cycle;
for j=1, 2, 3:
for i=1 upto j+1:
picture T; 
T=image(
flake(j, i, P, 15/16);
label("$(" & decimal j & "," & decimal i & ")$", 
point 1/2 of bbox currentpicture + 6 down);
);
draw T shifted (100j-120i, 140j);
endfor
endfor
endfig;
\end{mplibcode}
\end{document}

enter image description here

Hany
  • 4,709

1 Answers1

1

First, the answers to your stated questions:

  1. You could, by defining scl as a macro (see ch.10 of the MetaPost manual), though I would recommend turning it into a numerical variable instead and write the scaled out explicitly every time.
  2. You can if you say \mplibcodeinherit{enable} in your TeX source. See p.4 of the luamplib manual.
  3. You can define colour variables in MetaPost. See p.14f of the MetaPost manual, starting at the bottom paragraph.
  4. Modify the line draw T shifted (100j-120i, 140j);.

Now the underlying problem to these four questions seems to be that you are trying to use this scroll of MetaPost code without being able to read it. If that is so, a cursory reading through the MetaPost manual would really be worth your time. MetaPost is a strange little language, but weirdly simple if you do not try and go against the grain.

renkema
  • 431
  • 2
  • 8
  • @ renkema Thank you for your answer. I will try to apply your points. I tried to read the manual before I posted my question. It needs a lot of time to try to understand and implement the codes. I am accustomed to TikZ, and it is a whole new language for me. – Hany May 08 '23 at 10:15
  • @renkemaThe line draw T shifted (100j-120i, 140j); is for horizontal/vertical spacing between the whole figures (3,3) (3,2) and (3,3) (2,2); not for the spacing between the 7 groups (between each others) within the same figure (3,3) – Hany May 08 '23 at 12:12
  • I would just draw the polygons in programs that are designed for that, take screenshots, and input them into your tex file with \includegraphics{} – Nate Oct 05 '23 at 13:07