Path: 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 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 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