Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem passing parameters?

Status
Not open for further replies.

hydrocomputer

Programmer
Nov 29, 2004
6
0
0
US
Hello,

I thought I understood stack programming until I tried postscript. I cannot seem to pass parameters to a named function and get back a result, as in the following example (tested on ghostscript) any help?

0 0 1 setrgbcolor
/average {add 2 div} def
newpath
{
50 150 average % this should put 100 on the stack, right?
100 moveto 100 0 rlineto 0 100 rlineto -100 0 rlineto
closepath
} ufill
showpage
 
Your problem isn't the "average" procedure. It would leave "100" on the stack, if you let it.

The problem is that "ufill" expects a path. You're never actually creating a path, because you have those operators bracketed with curly braces.

Curly braces defer execution, and create an array. When you place that array back on the stack, it executes. That's why we call them "procedures" or "functions". They ain't, really. They are executable arrays.

My point is, nothing between "newpath" and "ufill" ever gets executed in your program.

The OTHER problem is that "ufill" expects a more complex path than you're creating. It needs a "self-intersecting" path, in order for the non-zero winding rule to have something to work on. You really just need "fill".

Code:
% set currentcolor in the graphics state:
0 0 1 setrgbcolor

% create key-value pair (name/array) in currentdict:
/average {add 2 div} def

% create a new path in graphics state:
newpath

% create a currentpoint in graphics state:
50 150 average 100 moveto 

% build a path in graphics state:
100 0 rlineto 0 100 rlineto -100 0 rlineto

% close that path with appropriate linejoin:
closepath

% fill the currentpath with the currentcolor:
fill

% "output" the page:
showpage



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top