[comp.lang.postscript] Npoly for your toolchest

hascall@atanasoff.cs.iastate.edu (John Hascall) (11/23/89)

   Here's another one for the old postscript toolchest...

   John Hascall / Iowa State Univ Comp Center / Ames IA

%!
/PROC {
%
% /NAME { #locals begin .... end }  PROC  -
%
	dup dup 0 get 0 exch dict put bind def
} bind def

%
% Create an N-sided regular polygon centered at (X,Y) inscribed in a circle of
% a given radius with the first point "offset" degrees from the X-axis.
%

/Npoly {
%
%  CENTERx CENTERy Radius Offset Width Nsides Npoly  -
%
	11 begin
		/Nsides			exch def
		/Width			exch def
		/Offset			exch def
		/Radius			exch def
		/Y			exch def
		/X			exch def

		/Delta	360 Nsides div	def
		/Angle	0		def
		/i	0		def
		/x	0		def
		/y	0		def

		gsave
			newpath
			0 1 Nsides 1 sub {
				/i exch def
				i Delta mul Offset add /Angle exch def
				Angle cos Radius mul X add /x exch def
				Angle sin Radius mul Y add /y exch def
				i 0 eq {
					x y moveto
				}{
					x y lineto
				} ifelse
			} for
			closepath
			Width setlinewidth
			stroke
		grestore
	end
} PROC

%
%  CENTERx CENTERy Radius Offset Gray Nsides  Npolyfill  -
%  is left as an exercise for the reader
%

% Here is a DEMO

300 300 200   0 3 8 Npoly
350 350 100  15 1 3 Npoly

showpage