c	program main
c	call gset							!  enter graphic mode
c	call view9
c	call aset							!  return to alpha mode
c	end	
c	-----------------------------------------------------------------------
	subroutine view9
c
c	...nine viewports demo; use of mid level routines
c
c	(C) Copyright 1988, 1989 by Jim Farrell      All Rights Reserved.
c
	integer gx1(9),gx2(9),gy1(9),gy2(9)
	integer x1,y1,x2,y2,xs,ys
c
	parameter(api=3.141592,a2pi=api*2,apio2=api/2)
	parameter (xpmax=1.0,xpmin=-1.0,ypmax=1.0,ypmin=-1.0)
	parameter (xdmax=639,xdmin=0,ydmax=199,ydmin=0)	!  display limits
	parameter (nx=3,ny=3,xs=5,ys=2)		!  no. and spacing in x & y
c
	call putstr(10,20,' DEMONSTRATION MULTIPLE VIEWS')
	call putstr(12,20,'    AND MID LEVEL ROUTINES ')
	call pause('WHEN READY ')			!  display message and pause
	call gcls
	irk=1							!  seed for random numbers
	call window(xpmin,ypmin,xpmax,ypmax)	!  set window
	xl=int((xdmax-xdmin-(nx+1)*xs)/nx)		!  viewport size
	yl=int(((ydmax-ydmin-(ny+1)*ys)-10)/ny)
	ig=0
	x2=0
	do 320 i=1,nx						!  set up the nine viewports
		x1=x2+xs
		x2=x1+xl
		y2=10
		do 310 j=1,ny
			y1=y2+ys
			y2=y1+yl
			ig=ig+1
			gx1(ig)=x1
			gx2(ig)=x2
			gy1(ig)=y1
			gy2(ig)=y2
			call view(x1,y1,x2,y2)		!  set viewport
			call grid9(xpmin,ypmin,xpmax,ypmax)
310		continue
320	continue
	dxp=xpmax-xpmin
	dyp=ypmax-ypmin
	ro=min(dxp,dyp)/2
c
c	...view port 1 - random clusters of points
c
	ig=1
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	do 340 i=1,10
		r=rand(irk)*ro
		x=((dxp-2.0*r)*(rand(irk)-0.5))
		y=((dyp-2.0*r)*(rand(irk)-0.5))
		do 330 j=1,50
			xp=x+r*(rand(irk)-0.5)
			yp=y+r*(rand(irk)-0.5)
			call point(xp,yp)
330		continue
340	continue
c
c	...viewport 2 - drunkards walk
c
	ig=2
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	r=ro
	xp=0.0
	yp=0.0
	do 360 i=1,50
350		continue
		x=xp+r*(rand(irk)-0.5)
		y=yp+r*(rand(irk)-0.5)
		if(x.lt.xpmin.or.x.gt.xpmax.or.
     1			y.lt.ypmin.or.y.gt.ypmax)goto 350	! hit the wall?
		call line(x,y,xp,yp)
		xp=x
		yp=y
360	continue
c
c	...viewport 3 - boxes
c
	ig=3
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	do 380 i=1,15
		x=dxp*(rand(irk)-0.5)
		y=dyp*(rand(irk)-0.5)
		xp=x*rand(irk)
		yp=y*rand(irk)
		call box(x,y,xp,yp)
380	continue
c
c	...viewport 4 - concentric circles
c
	ig=4
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	r=ro
	dr=r/10.0
	do 400 i=1,8
		call circle(0.0,0.0,r)
		r=r-r/8
400	continue
c
c	...viewport 5 - random circles
c
	ig=5
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	do 420 i=1,10
		r=rand(irk)*ro
		x=((dxp-2.0*r)*(rand(irk)-0.5))
		y=((dyp-2.0*r)*(rand(irk)-0.5))
		call circle(x,y,r)
420		continue
c
c	...viewport 6 - random points 
c
	ig=6
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	do 440 i=1,250
		x=(dxp*(rand(irk)-0.5))
		y=(dyp*(rand(irk)-0.5))
		call point(x,y)
440	continue
c
c	...viewport 7 - rotated ellipses
c
	ig=7
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	a=ro
	b=a/6
	dth=api/8
	do 460 i=1,8
		theta=dth*real(i-1)
		call ellipse(0.0,0.0,a,b,theta)
460	continue
c
c	...viewport 8 - rotated lines
c
	ig=8
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	r=ro
	da=api/real(8)
	do 480 i=1,8
		a=da*real(i-1)
		xp=r*sin(a)
		yp=r*cos(a)
		call line(-xp,-yp,xp,yp)
480	continue
c
c	...viewport 9 - spiral
c
	ig=9	
	call view(gx1(ig),gy1(ig),gx2(ig),gy2(ig))	!  set viewport
	r=ro
	dr=r/(48*8)
	xp=r
	yp=0.0
	da=a2pi/real(48)
	do 500 i=1,48*8
		a=da*real(i-1)
		x=r*cos(a)
		y=r*sin(a)
		call line(xp,yp,x,y)
		xp=x
		yp=y
		r=r-dr
500	continue
	call pause('REVIEW NINE PLOTS IN NINE VIEWS') !  done - wait for input 
	return
	end
c	------------------------------------------------------------------
	subroutine grid9(x1,y1,x2,y2)
c
c	...draw a grid in current viewport
c
	parameter (nx=3,ny=3)
c
	call box(x1,y1,x2,y2)		!  draw border
	dx=(x2-x1)/nx
	dy=(y2-y1)/ny
	do 210 i=1,nx				!  vertical grid lines
		x=x1+dx*real(i-1)
		call line(x,y1,x,y2)
210	continue
	do 220 i=1,ny				!  horizontal grid lines
		y=y1+dy*real(i-1)
		call line(x1,y,x2,y)
220	continue
	return
	end
