一种在路径中在每个载体上执行单独中风的方法

发布于 2025-02-06 08:13:49 字数 683 浏览 2 评论 0原文

我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑丑阿 2025-02-13 08:13:49

正如肯所说,您无法在路径迭代时修改路径。但是您可以捕获信息并稍后重播。

[
  { /move cvx 3 array astore cvx }
  { /line cvx 3 array astore cvx }
  { /curve cvx 7 array astore cvx }
  { /close cvx 1 array astore cvx }
  pathforall
]

这将所有内容保存在数组中。每个数组元素都是一个一些过程,其中包含点,并调用移动 line 曲线collect。您可以使用{exec} forall执行整个内容。

然后,您可以为每个名称定义自己的动作。我从原始运算符movetolineto等选择了不同的名称。因此,可以将它们定义为不同的事情而不会干扰真实的操作员。

类似以下定义应该做的或接近。

/move { moveto } def
/line { lineto currentpoint stroke #NextColor moveto } def
/curve { curveto } def
/close { closepath } def

这种方法的一个问题是,通过将顺序行段分为单独的线路,您可以防止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.

[
  { /move cvx 3 array astore cvx }
  { /line cvx 3 array astore cvx }
  { /curve cvx 7 array astore cvx }
  { /close cvx 1 array astore cvx }
  pathforall
]

This saves everything in an array. Each array element is a little procedure containing the points and a call to move line curve or close. 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.

/move { moveto } def
/line { lineto currentpoint stroke #NextColor moveto } def
/curve { curveto } def
/close { closepath } def

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 with strokepath fill and then replace the fill part of that with shfill. This would make a line drawing with all the appropriate joins added but with a smoothly changing color gradient that shfill can do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文