假设我已经建立了一条自行车道bulidcycle
:
path pa[];
pa.0:=(-6u,0){dir 90} .. (0,8u){dir 0};
pa.01:=pa.0 reflectedabout(origin, (0,1));
pa.1:=(-6u,0){dir -90} .. (0,-3u){dir 0};
pa.11:=pa.1 reflectedabout(origin, (0,1));
pa.2:=(3u,-6u)--(3u,12u);
pa.3:=buildcycle(pa.01,pa.11,pa.2);
draw pa.3 withcolor red;
然后就可以很容易地填充颜色了,
fill pa.3 withcolor red;
我的问题是如何用斜线填充它?
我们可以定义一个名为的函数,用方向上的线draw_fill(expr dr, pa)
填充路径吗?pa
dr
编辑
过了一会儿,我发现我们可以通过如下方式进行剪辑:首先定义一个名为的函数draw_clip
,
def draw_clip(expr pat, len, gap) =
begingroup
u:=10pt;
for i=-len upto len:
draw (-len*u*dir(40)--len*u*dir(40)) shifted (0,i*u*gap);
endfor;
clip currentpicture to pat;
endgroup;
enddef;
然后在绘制之前,进行剪辑:
draw_clip(pa.3,20,.5,40);
%continu your other draws
也许这不是一个完美的解决方案(因为你必须先剪辑它,然后才能进行任何其他绘制)。所以我的问题可以改为最好的方法是什么?
另一个小问题是,如果您想用标签标记区域,那么标签需要更改为类似
%fix the label
picture lab;
lab=thelabel.rt(btex $\Omega$ etex, (4u, 2u));
unfill bbox lab;
draw lab
答案1
还有其他使用包 (B. Jackowski) 的示例hatching
,我现在对包有了更多的了解。它相当简单,因为它重新定义了withcolor
图元,使其 rgb 参数成为阴影参数:坡度角、连续阴影线之间的空间、线宽。最后一个参数必须为负数,以避免与真实颜色参数混淆。
input hatching;
u := 1cm;
path circle; circle = fullcircle scaled 10u;
beginfig(1);
hatchfill circle withcolor (45, 5mm, -.5bp);
draw circle;
endfig;
end.
当然,可以使用以下命令(类似于可以使用的hatchingoptions
更强的命令)指定阴影的颜色和其他参数:drawoptions
input hatching;
u := 1cm;
path circle; circle = fullcircle scaled 10u;
beginfig(2);
hatchoptions (withcolor red dashed evenly);
hatchfill circle withcolor (-45, 7mm, -.5bp);
draw circle;
endfig;
end.
hatching
也可以使用任意图案代替直线,但我还没有尝试过。
希望有帮助!
答案2
您可以使用image
运算符来避免操作currentpicture
。下面是一个例子,展示了如何用斜线填充随机循环路径。
beginfig(1);
% make the filler
theta := 20; gap := 8; N := 10;
picture lines; lines = image(
for i=-N upto N:
draw ((left--right) scaled 100) rotated theta shifted (gap*i*up);
endfor );
% make a random shape
z0 = right scaled 50;
path shape; shape = z0 for i=1 upto 9: .. (z0 rotated 36i)+(uniformdeviate 10, uniformdeviate 10) endfor .. cycle;
% clip the filler to the shape and draw it, then draw the shape
clip lines to shape;
draw lines withcolor .674 red withpen pencircle scaled 0.1bp;
draw shape;
endfig;
这使得:
这是另一个形状规则但图案更随机的例子。
beginfig(2);
a := 3; L := 30;
picture waves; waves = image( for j=-20 upto 20:
draw ((-10L,0) for i=-9 upto 10: .. (i*L-3/4L,+a+normaldeviate){right}
.. (i*L-1/4L,-a+normaldeviate){right} .. (i*L,0)
endfor) shifted (uniformdeviate 1/5L, 3.5*a*j); endfor);
path shape; shape = fullcircle scaled 100;
clip waves to shape;
draw waves withcolor .66blue;
draw shape;
endfig;
这使得:
答案3
这只是 PSTricks 的另一种解决方案。
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(8,6)
\psset{fillstyle=vlines}
\pscircle(2,2){1}
\psccurve(6,5)(5,3)(4,2)(4,1)(7,3)(7,6)
\end{pspicture}
\end{document}