为了绘制不同类型的多边形,我使用以下修改自的代码答案 到这个帖子。最初的代码是为绘制五边形而设计的。
值得注意的是,当应用此修改后的代码绘制具有不同边数的其他多边形(三角形、四边形、六边形、八边形)时,需要进行大量工作来重新调整有关多边形边数与边之间角度的关系、缩放因子、每组多边形(中心多边形和周围多边形)的旋转角度、多边形之间的间距以及多边形组之间的间距的参数。
我的问题是:
1-为了方便编辑用于绘制不同类型多边形的上述参数,我需要将它们中的每一个设置为可以轻松修改的单独变量,而不需要像我在修改后的代码中那样在每种情况下手动执行此操作。
例如,我需要设置缩放变量,然后在需要的位置应用所需的值
设置变量:
scl=缩放 0.381966
那么不要说:
缩放 1.6424538(即 0.381966*4.3)
说:
顺时针*4.3
2- 是否可以将这些定义的变量放在文档的开头,而不是在每个 \begin{mplibcode} 之后重复它们
3- 是否可以定义要使用的颜色,而不是使用默认颜色
例如使用这样的东西:
\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- 如何固定最终复合图中各组之间的间距
\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}
答案1
首先,回答您提出的问题:
- 您可以通过定义
scl
为宏来(参见 MetaPost 手册的第 10 章),但我建议将其转换为数值变量并scaled
每次都明确写出。 - 如果你
\mplibcodeinherit{enable}
在 TeX 源中这样说,那么就可以了。请参阅 luamplib 手册第 4 页。 - 您可以在 MetaPost 中定义颜色变量。请参阅 MetaPost 手册第 14f 页,从底部段落开始。
- 修改该行
draw T shifted (100j-120i, 140j);
。
现在,这四个问题的根本问题似乎是,您试图使用这卷 MetaPost 代码,却无法阅读它。如果是这样,粗略地阅读 MetaPost 手册确实值得您花时间。MetaPost 是一种奇怪的小语言,但如果您不尝试逆潮流而行,它却出奇地简单。