[comp.lang.postscript] "Real World PostScript" example problems

brown@ftms.UUCP (Vidiot) (04/23/91)

Has anyone gotten the sample programs on pages 147 and 150 to work?  The first
one doesn't like the pf definition, i.e., it says that it is undefined and the
second one gives out a syntax error: nostringval

I have attached what I have typed in.  If someone has these working, I would
appreciate corrections.

Thanks in advance.


%!PS-Adobe1.0
%% Title: LookAtHalftoneCells
%% Creator: Bill Woodruff

/cs {dup stringwidth pop -2 div 0 rmoveto show} def

/msg {
	fn 14 scalefont setfont
	0 340 moveto
	(Plot of Halftone Cells and Order of Spot Function Action) cs
	currentpoint 30 sub exch neg exch moveto
	(Frequency = ) show f =string cvs show ( ... ) show
	(Angle = ) show a =string cvs show
	( ... ) show (Number of Pixels = ) show
	p =string cvs show
} def

/p 0 def
/pscreen {	%def
gsave
	2 copy
	/a exch def
	/f exch def
	gsave
		{/p dup load 1 add def 1} setscreen
	grestore

	/rad 20 def
	/pf dpi f dpi rad mul def

	a rotate
	gsave
		p 100 idiv dup 1 gt
		{1.5 exch div dup scale} {pop}
		ifelse

		p -1 1
		{
		/n exch def
		pf mul exch pf mul exch
		gsave
			translate 0 0 moveto
			gsave newpath 0 0 rad 0 360 arc fill grestore
			a neg rotate 0 -8 rmoveto
			1 setgray
			n =string cvs cs
		grestore
		}
		for
	grestore
	0 0 moveto
	.5 setgray .72 setlinewidth
	0 200 rlineto 0 -400 rlineto
	0 0 moveto
	200 0 rlineto -400 0 rlineto
	stroke
grestore
} def 	% /pscreen

306 390 translate 0 0 moveto

/fn /NewCenturySchlbk-Bold findfont def

fn 24 scalefont setfont

/dpi 72 0 dtransform dup mul exch dup mul add sqrt def

% put screen frequency and angle here
60 45 pscreen
msg
showpage


%!PS-Adobe
%Title: CountPixels.ps
%Creator: Henry Bortman

% The definition of the procedure actfreq uses 300 as a resolution.
% If you use this routine on an output device with a different
% resolution, you will have to change this number.

initgraphics grestoreall

%-----procedure definitions

/inch {72 mul} def
/xdf {exch def} def
/st 80 string def

/pnum {st cvs print} def

/boxpath {0 1 lineto 1 1 lineto 1 0 lineto closepath} def

/newspot {	% def
	dup mul exch dup mul add 1.0 exch sub
	/counter counter 1 add def
} def

/setUpScreen {freq angle /newspot load setscreen} def

/actfreq {
	300 counter sqrt div
} def	%change for different dpi

/writeMessage {
% angle is the nominal angle
% actfreq is the actual frequency
% counter is the actual number of pixels
	angle pnum ( ) print
	actfreq pnum ( ) print
	counter pnum (\n) print flush
} def

% begin main program

1 inch 5 inch translate
0 0 moveto
currentpoint
.1 inch .1 inch scale
boxpath

33 1 50	%set nominal greq range: start, increment, end
{/freq xdf
	(\n) print flush
	(nominal frequency: ) print freq pnum
	(\n) print fludh (\n) print flush
		0 1 45	%set angle range: start, increment, end
		{	%for
		/angle xdf
		/counter 0 def
		gsave
			setUpScreen .7 setgray fill
		grestore
		writeMessage
		) for
} for
-- 
harvard\
  ucbvax!uwvax!astroatc!ftms!brown
rutgers/
INTERNET: spool.cs.wisc.edu!astroatc!ftms!brown