我需要用 MetaPost 绘制一些这样的图表。
所以我想创建一个木纹填充函数并多次使用它。有什么好方法吗?
我想生成一个随机函数,绘制它的整数级曲线并缩放图片 --- 得到的图片应该让人想起木纹。但是我不知道如何在 MetaPost 中做这样的事情。Thruston 的回答似乎相关---希望有人能帮助我,我刚开始使用 MetaPost。
答案1
除了@mickep 的回答:遗憾的是,没有宏可以自动将 woodBlock 放入任意路径,现在我添加了一个(https://github.com/jemmybutton/fiziko/commit/bd24d7fa1144c722ede76e1b75378dc4ea0c1c50)你给它一个封闭的路径和一个角度作为参数,它会返回一个木质纹理图片(没有轮廓;更新:实际上,不,让轮廓保留)。例如,以下代码会产生类似于问题中的图片的内容:
input fiziko.mp;
pair A, B, C, D, E, F, C', E', F';
numeric totalWidth, width, height, breadth, a[];
path p[];
totalWidth := 5cm;
width := 2cm;
height := 3cm;
breadth := 1/3cm;
A := (0, 0);
B := (totalWidth, 0);
C := (1/2totalWidth, 0);
E := (xpart(C), height);
D := 3/4[C, E];
F := (xpart(E) + width, 0);
C' = whatever[C shifted (0, breadth), F shifted (0, breadth)]
= whatever[C shifted (breadth, 0), E shifted (breadth, 0)];
E' = whatever[E shifted (breadth, 0), C shifted (breadth, 0)]
= whatever[E shifted ((unitvector(E-F) scaled breadth) rotated 90), F shifted ((unitvector(E-F) scaled breadth) rotated 90)];
F' = whatever[C shifted (0, breadth), F shifted (0, breadth)]
= whatever[E shifted ((unitvector(E-F) scaled breadth) rotated 90), F shifted ((unitvector(E-F) scaled breadth) rotated 90)];
p1 := A -- B -- B shifted (0, -breadth) -- A shifted (0, -breadth) -- cycle;
a1 := 0;
p2 := C -- E -- E' -- C' -- cycle;
a2 := 90;
p3 := E -- F -- F' -- E' -- cycle;
a3 := angle (E-F);
p4 := C -- F -- F' -- C' -- cycle;
a4 := 0;
for i := 1 step 1 until 4:
draw woodenThing(p[i], a[i]);
% draw p[i];
endfor;
dotlabel.top("A", A);
dotlabel.urt("B", B);
dotlabel.ulft("C", C);
dotlabel.lft("D", D);
dotlabel.ulft("E", E);
还有一些影响纹理的全局变量:https://github.com/jemmybutton/fiziko/blob/master/fiziko.mp#L1660
答案2
我刚刚了解到很棒的 MetaPost 包菲齐科由@sergey-slyusarev 创建。
代码(我使用 ConTeXt 生成这个最小示例,使用 LaTeX 会类似)
\startMPpage[offset=2bp]
input fiziko.mp
draw woodBlock(10cm,1cm);
\stopMPpage
生成输出
我没有研究代码来了解如何轻松地将形状从矩形更改为任意闭合路径。
答案3
这是答案的开始。需要做更多工作才能使其强大且易于重复使用....
prologues := 3;
outputtemplate := "%j%c.eps";
vardef wavy expr pa =
point 0 of pa
for a = s step s until arclength(pa):
.. point arctime(a) of pa of pa
shifted (unitvector(direction arctime(a) of pa of pa)
rotated 90 scaled 1/8 normaldeviate)
endfor
enddef;
beginfig(1);
numeric s; s = 10;
path p, q;
p = (left--right) scaled 200;
for i=-10 upto 10:
draw wavy p shifted (2i*up) rotated -5
withpen pencircle xscaled 1/2 yscaled 1/8 rotated 15
withcolor 1/256(79,36,19);
endfor
q = unitsquare shifted -(1/2,1/2) xscaled 144 yscaled 21;
clip currentpicture to q; undraw q withpen pencircle scaled 1; draw q;
endfig;
end.