🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #1358

Procedures, dictionaries & the toolchest

#1358
From: John Hascall
Date: Wed, 22 Nov 1989 20:45
76 lines
2410 bytes
   A while back, some interesting postscript procedures were posted
by Clayton E. Cramer prompting a reply by Glenn Reid (of Adobe)
regarding ways to define procedures so as to encapsulate dictionary
entries (efficiently).

   Anyway, here is a modification (improvement?) of their ideas:

John Hascall  /  ISU Comp Ctr.  /  Ames, IA


%!
%! define the procedure defining procedure :-)
%!

/PROC {
%
%  /NAME { #locals begin .... end }  PROC  -
%
        dup        % /NAME {#...} {#...}
        dup        % /NAME {#...} {#...} {#...}
        0 get      % /NAME {#...} {#...} #locals
        0 exch     % /NAME {#...} {#...} 0 #locals
        dict       % /NAME {#...} {#...} 0 <dictionary with room for #locals>
        put        % /NAME {D...}
        bind       % /NAME {D...}
        def        %
} bind def


%!
%! Now define a procedure to do pie chart slices as an example
%!

/PieSlice {
%
% CENTERx CENTERy ANGLE0 ANGLE1 RADIUS GRAY LINEWIDTH  PieSlice  -
%
        7 begin        
                /Width          exch def
                /Gray           exch def
                /Radius exch def
                /Angle1 exch def
                /Angle0 exch def
                /Y       exch def
                /X       exch def

                gsave
                        newpath
                        X Y moveto
                        currentpoint Radius Angle0 Angle1 arc
                        closepath
                        Width setlinewidth
                        Gray setgray
                        fill
                grestore
        end
} PROC


%!
%! make a pie with 5 slices
%!

300 300  45  75 200 0.00 2 PieSlice
300 300 120  45 200 0.15 2 PieSlice
300 300 165  90 200 0.30 2 PieSlice
300 300 255 105 200 0.45 2 PieSlice
300 300   0  45 200 0.60 2 PieSlice


%!
%! show the page
%!

showpage
Technical Details
Message-ID: <2012@atanasoff.cs.iastate.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!atanasoff.cs.iastate.edu!hascall

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!atanasoff.cs.iastate.edu!hascall
From: hascall@atanasoff.cs.iastate.edu (John Hascall)
Newsgroups: comp.lang.postscript
Subject: Procedures, dictionaries & the toolchest
Message-ID: <2012@atanasoff.cs.iastate.edu>
Date: 22 Nov 89 20:45:57 GMT
Sender: hascall@atanasoff.cs.iastate.edu
Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall)
Distribution: na
Organization: Iowa State Univ. Computation Center
Lines: 76