C     FRACPTS.F
C     A PROGRAM TO ITERATE A FRACTAL IMAGE DEFINED BY SEVERAL POINTS.

C     ORIGINALLY WRITTEN 1994 WHILE A STUDENT AT UNIV OF WISCONSIN-
C     RIVER FALLS.

C     COPYRIGHT (C) 1994, 2007 JIM HALL, JHALL@FREEDOS.ORG
C Permission is hereby granted, free of charge, to any person obtaining
C a copy of this software and associated documentation files (the
C "Software"), to deal in the Software without restriction, including
C without limitation the rights to use, copy, modify, merge, publish,
C distribute, sublicense, and/or sell copies of the Software, and to
C permit persons to whom the Software is furnished to do so, subject to
C the following conditions:
C
C The above copyright notice and this permission notice shall be
C included in all copies or substantial portions of the Software.
C
C THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
C EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
C MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
C NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
C LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
C OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
C WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

C     THINGS TO TRY:
C
C     1. EXPERIMENT WITH BETA ... SMALL VALUES (.3) GIVE AN INTERESTING
C     PATTERN, BUT LARGER VALUES (.9) GIVE A "SMEARED" PATTERN.
C
C     2. CHANGE THE NUMBER OF ATTRACTORS AND THEIR PLACEMENT
C
C     3. BETA=.5 WITH 3 ATTRACTORS SHOULD GENERATE A FAMILIAR PATTERN.

      PROGRAM FRACPTS
      PARAMETER (MAXITER = 30000)
      PARAMETER (BETA = .25)
      PARAMETER (MAXATTR = 4)
      REAL X(MAXATTR), Y(MAXATTR)

C     DEFINE THE ATTRACTORS

      X(1) = 1.
      Y(1) = 1.

      X(2) = 80.
      Y(3) = 1.

      X(3) = 1.
      Y(3) = 80.

      X(4) = 80.
      Y(4) = 80.

C      X(5) = 60.
C      Y(5) = 20.
C
C      X(6) = 20.
C      Y(6) = 60.

C     GENERATE THE FRACTAL IMAGE

      PRINT *, '## USE GNUPLOT TO DISPLAY THE RESULTS'
      X0 = 0.
      Y0 = 0.

      DO I = 1, MAXITER, 1
C     CHOOSE AN ATTRACTOR
         J = INT(RAND(0) * 6.) + 1

C     NOW ITERATE THE NEXT POINT
         X0 = BETA * (X0 - X(J)) + X(J)
         Y0 = BETA * (Y0 - Y(J)) + Y(J)
         PRINT *, X0, Y0
      ENDDO
      END