% Get coordinates of ith vertex
% i getvertex
/getvertex {
	% i on stack
	/theta exch 360 mul p div def
	theta cos radius mul ctr_x add
	theta sin radius mul ctr_y add
} def

% p center_x center_y radius drawpaley
/drawpaley {
	/radius exch def
	/ctr_y exch def
	/ctr_x exch def
	/p exch def

	% Define visited array to mark which edges have been drawn
	/visited p array def
	0 1 p 1 sub {
		/row p array def
		0 1 p 1 sub {
			row exch false put
		} for
		visited exch row put
	} for
	
	newpath
	
	0 1 p 1 sub {
		/i exch def
		1 1 p 1 sub 2 idiv {
			/j exch 2 exp i add p mod def
			visited i get j get {
				i getvertex moveto
				j getvertex lineto
				visited i get j true put
				visited j get i true put
			} if
		} for
	} for
	
	stroke
	
} def

17 306 396 100 drawpaley

showpage

% Get coordinates of ith vertex
% i getvertex
/getvertex {
	% i on stack
	/theta exch 360 mul p div def
	theta cos radius mul ctr_x add
	theta sin radius mul ctr_y add
} def

% p center_x center_y radius drawpaley
/drawpaley {
	/radius exch def
	/ctr_y exch def
	/ctr_x exch def
	/p exch def

	% Define visited array to mark which edges have been drawn
	/visited p array def
	0 1 p 1 sub {
		/row p array def
		0 1 p 1 sub {
			row exch false put
		} for
		visited exch row put
	} for
	
	newpath
	
	0 1 p 1 sub {
		/i exch def
		1 1 p 1 sub 2 idiv {
			/j exch dup mul i add p mod def
			visited i get j get {
				i getvertex moveto
				j getvertex lineto
				visited i get j true put
				visited j get i true put
			} if
		} for
	} for
	
	stroke
	
} def

17 306 396 100 drawpaley

showpage
