home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / NeXTSTEPAdvantage / Plotter / drawingFuncs.psw < prev    next >
Text File  |  1991-06-28  |  2KB  |  85 lines

  1. /*
  2.  * drawingFuncs.psw  
  3.  *
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or implied, as to its
  6.  * fitness for any particular use.
  7.  *
  8.  */ 
  9.  
  10. defineps loadPSProcedures()
  11.     /xpos 0 def
  12.     /ypos 0 def
  13.     /ticklength [8 2 2 2 2 5 2 2 2 2] def
  14.  
  15.     % x 
  16.     /getticklength {10 idiv 10 mod abs ticklength exch get} def
  17.  
  18.  
  19.     % x y length     
  20.     /vtick { moveto 0 exch rlineto stroke } def
  21.     /htick { moveto 0 rlineto stroke } def
  22.     
  23.     % x     
  24.     /increase-x {/xpos xpos 10 add def} def
  25.     /decrease-x {/xpos xpos 10 sub def} def
  26.  
  27.     % y     
  28.     /increase-y {/ypos ypos 10 add def} def
  29.     /decrease-y {/ypos ypos 10 sub def} def
  30. endps
  31.  
  32. defineps drawCircle(float x, y, radius)
  33.     % describe the path of a circle
  34.     newpath
  35.     x y radius 0 360 arc
  36.     closepath
  37.     stroke
  38. endps
  39.  
  40. defineps drawAxes(float x, y, width, height)
  41.     gsave
  42.         % set max and min of visible area
  43.         /xmax x width add 1 sub def
  44.         /ymax y height add def
  45.         /ymin y 1 add def
  46.         /xpos 0 def
  47.         /ypos 0 def
  48.  
  49.         % draw border
  50.         x ymin moveto
  51.         x ymax lineto
  52.         xmax ymax lineto
  53.         xmax ymin lineto
  54.         closepath
  55.         stroke
  56.  
  57.         % now draw axes
  58.         x 0 moveto
  59.         xmax 0 lineto
  60.         stroke
  61.         0 ymin moveto
  62.         0 ymax lineto
  63.         stroke
  64.         0 0 moveto
  65.         % draw the pos x ticks
  66.         {xpos xmax le
  67.             {xpos getticklength neg xpos 0 vtick increase-x}{exit} ifelse
  68.         } loop
  69.         % draw the neg x ticks
  70.         0 0 moveto
  71.         {xpos x ge
  72.             {xpos getticklength neg xpos 0 vtick decrease-x}{exit} ifelse
  73.         } loop
  74.         % draw the pos y ticks
  75.         0 0 moveto
  76.         {ypos ymax le
  77.             {ypos getticklength neg 0 ypos htick increase-y}{exit} ifelse
  78.         } loop
  79.         % draw the neg y ticks
  80.         0 0 moveto
  81.         {ypos ymin ge
  82.             {ypos getticklength neg 0 ypos htick decrease-y}{exit} ifelse
  83.         } loop
  84.     grestore
  85. endps