In simple drawing programs I keep running into the very minor
problem that you have to call 'moveto' on the first point but
then 'lineto' on all the other points to put a line segment into
the path. It is very minor. But it keeps on happening.
This last time around I had my points all nicely packed into
an array of array. Lovely. And that led to this function which
I haven't found the right name for:
/fx,mapgxs { % a f g . [a0 f] [a1 g .. aN g]
3 1 roll exch dup first % g f a a0
3 -1 roll [ 3 1 roll exec ] % g a [a0 f]
3 1 roll rest exch map % [a0 f] [a1 g .. aN g]
} def
/first{ 0 get } def
/rest{ 1 1 index length 1 sub getinterval } def
/map { 1 index xcheck 3 1 roll [ 3 1 roll forall ] exch {cvx} if } def
Which you call like this:
/draw { % [[x0 y0]..[xN yN]] . -
{aload pop moveto} {aload pop lineto} fx,mapgxs pop pop
closepath
} def
Looking over some old code just now I found a completely
different approach to the same problem, by redefining the
thing to call. The `currentpoint stroke moveto` is just to "animate"
the drawing.
/newline { /line {moveto /line {lineto currentpoint stroke moveto} store} store } def
Which you could use like this (remove the "currentpoint stroke moveto"
above for closepath to work):
/draw {
newline {aload pop line} forall
closepath
} def
Are there other solutions? Is this a problem for anyone else?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 61:36:24 |
Calls: | 6,654 |
Files: | 12,200 |
Messages: | 5,331,534 |