postscript - Updating a variable in a procedure called multiple tmies -
i'm trying generate postscript "bitmap" making repeated calls block-drawing procedure.
rather define position of block on each call, i'd procedure update starting position automatically, based on known block size of (say) 100 pixels, this:
% starting position /px { 72 } def /py { 720 } def % block-drawing procedure, input= r-g-b /block { setrgbcolor px py moveto 0 100 rlineto 100 0 rlineto 0 100 neg rlineto fill % adjust px , py 100 , -100, ahead of next call } def % draw 3 increasingly lighter boxes, automatically shifted 0 0 0 box .25 .25 .25 box .5 .5 .5 box % etc...
is there simple way of achieving this?
yes, alter values of px , py.
note code defines px , py executable arrays, which, when executed, leave value on operand stack. there no need that, this:
/px 72 def /py 720 def
works well.
i think missing fact 'def
' associates key , value in current dictionary. since haven't started new dictionary, default one, userdict
. if use 'def
' again, associates new value same key in dictionary.
so if do:
% starting position /px 72 def /py 720 def % block-drawing procedure, input= r-g-b /block { setrgbcolor px py moveto 0 100 rlineto 100 0 rlineto 0 100 neg rlineto fill % adjust px , py 100 , -100, ahead of next call px 100 add /px exch def py 100 sub /py exch def } def % draw 3 increasingly lighter boxes, automatically shifted 0 0 0 box .25 .25 .25 box .5 .5 .5 box % etc...
that seem want.
Comments
Post a Comment