$INCLUDE: 'C:\FG\INTRFACE.FOR'

      PROGRAM MAIN

      INTEGER*2 AREA
      INTEGER*2 COLOR, OLD_COLOR
      INTEGER*2 LEFT
      INTEGER*2 MAX_COLOR, MAX_X, MAX_Y
      INTEGER*2 NEW_MODE, OLD_MODE
      INTEGER*2 X, Y
      INTEGER*2 FG_AUTOMODE, FG_GETMAXX, FG_GETMAXY
      INTEGER*2 FG_GETMODE, FG_GETPIXEL
      INTEGER*2 RANDOM

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

      IF (NEW_MODE .EQ. 4) THEN
         MAX_COLOR = 3
      ELSE IF (NEW_MODE .EQ. 11 .OR. NEW_MODE .EQ. 17) THEN
         MAX_COLOR = 1
      ELSE IF (NEW_MODE .EQ. 19) THEN
         MAX_COLOR = 255
      ELSE
         MAX_COLOR = 15
      END IF

      LEFT = 100
      MAX_X = FG_GETMAXX() - 1
      MAX_Y = FG_GETMAXY() - 1

10    IF (LEFT .GT. 0) THEN

         X = RANDOM(1,MAX_X)
         Y = RANDOM(1,MAX_Y)

         AREA = FG_GETPIXEL(X-1,Y-1) + FG_GETPIXEL(X,Y-1) +
     +          FG_GETPIXEL(X+1,Y-1) + FG_GETPIXEL(X-1,Y) +
     +          FG_GETPIXEL(X,Y)     + FG_GETPIXEL(X+1,Y) +
     +          FG_GETPIXEL(X-1,Y+1) + FG_GETPIXEL(X,Y+1) +
     +          FG_GETPIXEL(X+1,Y+1)

         IF (AREA .EQ. 0) THEN
            COLOR = RANDOM(1,MAX_COLOR)
            CALL FG_SETCOLOR(COLOR)
            CALL FG_POINT(X,Y)
            LEFT = LEFT - 1
         END IF

         GO TO 10
      END IF

      CALL FG_WAITKEY

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END

      INTEGER*2 FUNCTION RANDOM(MIN,MAX)

      INTEGER*2 MIN, MAX
      INTEGER*2 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
