$INCLUDE: 'C:\FG\FASTGRAF.FI'

      PROGRAM MAIN

      INTEGER RECTANGLES
      PARAMETER (RECTANGLES=200)

      INTEGER I
      INTEGER MINX, MAXX, MINY, MAXY
      INTEGER OLD_MODE
      INTEGER XRES, YRES
      INTEGER FG_AUTOMODE, FG_GETMAXX, FG_GETMAXY, FG_GETMODE
      INTEGER RANDOM

      CALL FG_INITPM
      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(FG_AUTOMODE())

      XRES = FG_GETMAXX()
      YRES = FG_GETMAXY()

      DO 10 I = 1,RECTANGLES
         MINX = RANDOM(0,XRES)
         MAXX = RANDOM(0,XRES)
         MINY = RANDOM(0,YRES)
         MAXY = RANDOM(0,YRES)
         IF (MINX .GT. MAXX) CALL SWAP(MINX,MAXX)
         IF (MINY .GT. MAXY) CALL SWAP(MINY,MAXY)
         CALL FG_SETCOLOR(RANDOM(0,15))
         CALL FG_RECT(MINX,MAXX,MINY,MAXY)
10    CONTINUE

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END

      INTEGER FUNCTION RANDOM(MIN,MAX)

      INTEGER MIN, MAX
      INTEGER SEED, TEMP

      DATA SEED /12345/

      TEMP = IEOR(SEED,ISHFT(SEED,-7))
      SEED = IAND(IEOR(ISHFT(TEMP,8),TEMP),#7FFF)
      RANDOM = MOD(SEED,MAX-MIN+1) + MIN

      RETURN
      END

      SUBROUTINE SWAP(VAR1,VAR2)
      INTEGER VAR1, VAR2
      INTEGER TEMP

      TEMP = VAR1
      VAR1 = VAR2
      VAR2 = TEMP

      RETURN
      END
