我正在尝试更改由 John Hobby 制作的盒子的背景颜色和文本颜色boxit.bb1()
,并尝试从他的手册中查找,drawoptions
但我找不到任何相关内容。任何帮助我都会很感激。谢谢。
答案1
不是恶意的,但是第 5 页手动的实际上说明了如何添加颜色。只需调整建议的示例:
vardef drawpink(text t) =
fixsize(t);
forsuffixes s=t:
%Use another color ad libitum
fill bpath.s withcolor 3/4[red,white];
drawboxed(s);
endfor
enddef;
%Uncomment or change if you work in standalone MetaPost.
%It also works for circleit
%beginfig(1)
boxit.a(btex Box 1 etex);
boxit.b(btex Box 2 etex);
b.n = a.s - (0,20pt);
drawpink(a,b);
drawarrow a.s -- b.n;
%endfig
%end
显然,如果这不是您想要询问的,您必须提供具体条件。
编辑:我错过了你对彩色文本的评论。以下内容改编自boxes.mp
。你可以继续进一步定制,但这会导致一些过于繁琐的事情。
def docoloredboxed(text t)(expr c, cc) =
fixsize(t); fixpos(t);
forsuffixes s=t:
draw bpath.s withcolor c; %Frame
draw pic_mac_.s withcolor cc; %Text
endfor
enddef;
vardef drawcoloredboxed(text t)(expr c, cc, ccc) =
fixsize(t);
forsuffixes s=t:
%Use another color ad libitum
fill bpath.s withcolor c; %Background
docoloredboxed(s)(cc, ccc);
endfor
enddef;
%Uncomment for standalone MetaPost
%beginfig(0);
boxit.a(btex Box 1 etex);
boxit.b(btex Box 2 etex);
b.n = a.s - (0,20pt);
%Background, frame and text in respective order
drawcoloredboxed(a,b)(3/4[red,white],red,1/2green);
drawarrow a.s -- b.n;
%endfig;
%end
答案2
您可能已经发现,boxes.mp
它隐藏了一定程度的复杂性,而且并不总是很直观。因此,这里有一个简单的替代方案,向您展示如何使用内置路径创建框unitsquare
,然后填充和绘制它们,并添加彩色标签,drawoptions()
如手册中所述。
prologues := 3;
outputtemplate := "%j%c.%{outputformat}";
beginfig(1);
path box[];
box1 = unitsquare xscaled 34 yscaled 13;
box2 = box1 shifted (21, -55);
drawoptions(withcolor 7/8[blue, white]);
fill box1;
fill box2;
drawoptions(withcolor 2/3 blue);
interim ahangle := 30;
drawarrow center box1 -- center box2 cutbefore box1 cutafter box2;
draw box1;
draw box2;
label("First", center box1);
label("Second", center box2);
drawoptions();
endfig;
end.
如果你编译它,mpost
你应该得到如下结果:
专业提示:对于稍短的箭头,请
bbox
在目标路径名前添加。drawarrow center box1 -- center box2 cutbefore box1 cutafter bbox box2;