$storage:2
$include:'egafort.h'
        IMPLICIT INTEGER*2 (I-N)
        CHARACTER*10 IZC
	DIMENSION JCOL(11)
        WRITE(*,*)' Demo program for EGA.'
        WRITE(*,*)' To begin hit return'
        READ(*,1000)IZC
1000    FORMAT(A10)
        IDRAW=0
        CALL SETMOD(16)
        CALL ZSETUP
1       DO 2 I=1,11
2           JCOL(I)=0
        CALL RECTFILL(0,0,639,349,0)
        DO 5  I=1,11
3	    ICOL=RAN()*25.+1.1
	    DO 4 J=1,11
4	        IF(ICOL.EQ.JCOL(J))GOTO 3
	    JCOL(I)=ICOL
            IF(RAN().GT..6)THEN
  	        CALL BLOT(ICOL)
	    ELSE
     	        CALL SLUG(ICOL)
            ENDIF
5	CONTINUE
        CALL SLEEP(4)
        GOTO 1
	END
	SUBROUTINE BLOT(ICOL)
	IMPLICIT INTEGER*2 (I-N)
        IXCEN=639.*RAN()
	IYCEN=349.*RAN()
	DO 1 I=1,25
  	    IRAD=4.+12.*RAN()
	    RADIUS=70.*RAN()
	    ANG=6.28*RAN()
	    IX=RADIUS*SIN(ANG)
	    IY=.8*RADIUS*COS(ANG)
	    CALL FCIRC(IXCEN+IX,IYCEN+IY,IRAD,ICOL)
1	CONTINUE
	RETURN
	END
	SUBROUTINE SLUG(ICOL)
        IMPLICIT INTEGER*2 (I-N)
	DIMENSION WIDTH(12),SINTAB(0:32)
        DATA IFIRST/0/
        IF(IFIRST.EQ.0)THEN
            DO 1 I=0,32
1           SINTAB(I)=SIN(3.1415926*I/16.)
            IFIRST = 1
        ENDIF
	DO 2 I=1,12
2	WIDTH(I)=5.05*RAN()
	IX=320.+160.*RAN()
	IY=175.+90.*RAN()
	DTHET=6.28*RAN()
	DR=1.5+2.5*RAN()
	DX=DR*SIN(DTHET)
	DY=DR*COS(DTHET)
	DIST=0.
	DIST2=0.
	DO 5 I=1,60
	DTHET=1.6*RAN()
	IF(DTHET.LT..8)DTHET=DTHET-1.6
	CCOS=.05*COS(DTHET)
	SSIN=.05*SIN(DTHET)
	DDX=DX*CCOS+DY*SSIN-.05*DX
	DDY=DY*CCOS-DX*SSIN-.05*DY
	DO 4 J=1,20
 	    DX=DX+DDX
	    DY=DY+DDY
	    IX2=IX+DX
	    IY2=IY+DY
	    DIST2=DIST2+DX
	    DIST=DIST+DR
	    IF(DIST.GE.1.3)THEN
  	        DIST=0.
	        WD=0.
	        DO 3 LL=1,6
                    MSIN = IAND(IFIX(DIST2*WIDTH(LL+6)),31)
3	            WD=WD+WIDTH(LL)*SINTAB(MSIN)
	        IWD=ABS(WD)+4.
	        CALL FCIRC(IX,IY,IWD,ICOL)
            ENDIF
	    IX=IX2
	    IY=IY2
	    IF(IX.GT.690)IX=IX-750
	    IF(IY.GT.400)IY=IY-450
	    IF(IX.LT.-50)IX=IX+750
	    IF(IY.LT.-50)IY=IY+450
4	    CONTINUE
        IF(INTEST().NE.0)THEN
            CALL SETMOD(3)
            STOP
        ENDIF
5	CONTINUE
	RETURN
	END
        FUNCTION RAN()
        IMPLICIT INTEGER*4 (L)
        IMPLICIT INTEGER*2 (M-N)
        DIMENSION M(2)
        EQUIVALENCE (M(1),L2)
        DATA IFIRST/0/
        IF(IFIRST.EQ.0)THEN
            CALL GETTIM(ID1,ID2,ITT2,ITT1)
            L1=ITT1+100*ITT2
            IF(MOD(L1,2).EQ.0)L1=L1+1
            IFIRST = 1
        ENDIF
        L2=L1
        M(2)=0
        L2=L2*259
        M(2)=0
        RAN=L2/65536.
        L1=L2
        RETURN
        END
        SUBROUTINE FCIRC(IX,IY,ISIZ,ICOL)
        IMPLICIT INTEGER*2 (I-N)
        DIMENSION ICOLSO(46),ICOLSI(46)
        DATA ICOLSO/1,1,1,1,1,1,1,1,
     1              2,2,2,2,3,3,
     2              4,4,4,4,4,4,4,
     3              5,5,5,6,6,6,6,6,6,
     4              7,8,8,8,8,
     5              9,9,9,9,9,
     6              12,12,12,12,12,13/
        DATA ICOLSI/2,6,7,9,10,12,13,14,
     1              1,10,14,15,12,14,
     2              2,7,9,10,12,13,14,
     3              2,7,13,2,3,7,10,14,15,
     4              14,9,11,12,13,
     5              2,7,10,13,14,
     6              2,7,9,10,15,15/
        ISIZ2 = (ISIZ*8)/10
        CALL FILLELIP(IX,IY,ISIZ,ISIZ2,ICOLSI(ICOL))
        CALL ELLIPSE(IX,IY,ISIZ,ISIZ2,ICOLSO(ICOL))
        RETURN
        END
        subroutine sleep(isleep)
        implicit integer*2 (a-z)
        call gettim(ihr,imin,isec,itic)
        isec = isec+isleep
        if(isec.gt.59)then
            isec = isec-60
            imin = imin+1
        endif
        if(imin.gt.59)then
            imin = imin-60
            ihr = ihr+1
        endif
        if(ihr.eq.23)then
            ihr = 0
        endif
1       call gettim(ihr1,imin1,isec1,itic)
        if(ihr1.ne.ihr.or.imin.ne.imin1.or.isec.ne.isec1)goto 1
        return
        end
