
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS).



Task

Create this fractal fern, using the following transformations:

 ƒ1   (chosen 1% of the time)
        xn + 1 = 0
        yn + 1 = 0.16 yn

 ƒ2   (chosen 85% of the time)
        xn + 1 = 0.85 xn + 0.04 yn
        yn + 1 = −0.04 xn + 0.85 yn + 1.6

 ƒ3   (chosen 7% of the time)
        xn + 1 = 0.2 xn − 0.26 yn
        yn + 1 = 0.23 xn + 0.22 yn + 1.6

 ƒ4   (chosen 7% of the time)
        xn + 1 = −0.15 xn + 0.28 yn
        yn + 1 = 0.26 xn + 0.24 yn + 0.44.

Starting position: x = 0, y = 0




 100  LET YY(1) = .16
 110  XX(2) =    .85:XY(2) = .04
 120  YX(2) =  - .04:YY(2) = .85
 130  LET Y(2) = 1.6
 140  XX(3) = .20:XY(3) =  - .26
 150  YX(3) = .23:YY(3) =    .22
 160  LET Y(3) = 1.6
 170  XX(4) =  - .15:XY(4) = .28
 180  YX(4) =    .26:YY(4) = .24
 190  LET Y(4) = .44
 200  HGR :I =  PEEK (49234)
 210  HCOLOR= 1
 220  LET X = 0:Y = 0
 230  FOR I = 1 TO 100000
 240      R =  INT ( RND (1) * 100)
 250      F = (R < 7) + (R < 14) + 2
 260      F = F - (R = 99)
 270      X = XX(F) * X + XY(F) * Y
 280      Y = YX(F) * X + YY(F) * Y
 290      Y = Y + Y(F)
 300      X% = 62 + X * 27.9
 320      Y% = 192 - Y * 19.1
 330      HPLOT X% * 2 + 1,Y%
 340  NEXT
 