一种在路径中在每个载体上执行单独中风的方法
我正在尝试使用PathForall在路径中绘制的每条线上应用不同的颜色。当我将“笔触”放在最后时,显然只会在最近的颜色中绘制形状。每种颜色更改后如何执行中风? /lineto的功能块不接受其中的“笔触”。 这是我的代码:
/Arial 12 selectfont
/color 6 def
/s 20 string def
1 setlinewidth
/#NextColor{
color 10 gt
{
0
/color exch def
}
{
color 4 add
/color exch def
color 8 div color 15 div color 19 div setrgbcolor
color 8 div s cvs show
( ) show
}
ifelse
} def
300 300 translate
-72 -72 moveto 72 -72 lineto 72 72 lineto -72 72 lineto -72 -72 lineto -100 -100 lineto 100 -100 lineto 100 100 lineto -100 100 lineto -100 -100 lineto
{/moveto load}
{/lineto load #NextColor }
{/curveto load}
{/closepath load}
pathforall
stroke
I'm trying to use pathforall to apply a different color to each line drawn in a path. When i put "stroke" at the end, it obviously only draws the shape in most recent color. How can i execute a stroke after each color change? The function block of /lineto doesnt accept "stroke" in it.
Here's my code:
/Arial 12 selectfont
/color 6 def
/s 20 string def
1 setlinewidth
/#NextColor{
color 10 gt
{
0
/color exch def
}
{
color 4 add
/color exch def
color 8 div color 15 div color 19 div setrgbcolor
color 8 div s cvs show
( ) show
}
ifelse
} def
300 300 translate
-72 -72 moveto 72 -72 lineto 72 72 lineto -72 72 lineto -72 -72 lineto -100 -100 lineto 100 -100 lineto 100 100 lineto -100 100 lineto -100 -100 lineto
{/moveto load}
{/lineto load #NextColor }
{/curveto load}
{/closepath load}
pathforall
stroke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如肯所说,您无法在路径迭代时修改路径。但是您可以捕获信息并稍后重播。
这将所有内容保存在数组中。每个数组元素都是一个一些过程,其中包含点,并调用
移动
line
曲线
或collect
。您可以使用{exec} forall
执行整个内容。然后,您可以为每个名称定义自己的动作。我从原始运算符
moveto
,lineto
等选择了不同的名称。因此,可以将它们定义为不同的事情而不会干扰真实的操作员。类似以下定义应该做的或接近。
这种方法的一个问题是,通过将顺序行段分为单独的线路,您可以防止PostScript实现在每个段之间绘制“联接”。这可能会在尖角上产生次优的外观。
考虑目标是否更适度地说为“变色线”,您可以用
stroke
streoth PathS Fill
替换fill <
fill < /code>shfill
的一部分。这将使添加了所有适当连接的线路绘图,但是shfill
可以做到的平稳变化的颜色梯度。As Ken says, you can't modify the path while iterating through the path. But you can capture the information and replay it later.
This saves everything in an array. Each array element is a little procedure containing the points and a call to
move
line
curve
orclose
. You can execute the whole thing with{exec} forall
.Then you can define your own actions for each of the names. I chose different names from the original operators
moveto
,lineto
, etc. so they can be defined to do something different without interfering with the real operators.Something like the following definitions ought to do it, or come close.
One problem with this approach is that by breaking up sequential line segments into separate lines, you prevent the PostScript implementation from drawing the "joins" between each segment. This may create a suboptimal appearance at corners with sharp angles.
Another approach to consider if the goal is more modestly stated as "a color-changing line" is you could replace
stroke
withstrokepath fill
and then replace thefill
part of that withshfill
. This would make a line drawing with all the appropriate joins added but with a smoothly changing color gradient thatshfill
can do.