
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 PROGRAM "Fern.bas"
110 RANDOMIZE 
120 SET VIDEO MODE 1:SET VIDEO COLOR 0:SET VIDEO X 40:SET VIDEO Y 27
130 OPEN #101:"video:"
140 DISPLAY #101:AT 1 FROM 1 TO 27
150 SET PALETTE BLACK,GREEN
160 LET MX=16000:LET X,Y=0
170 FOR N=1 TO MX
180   LET P=RND(100)
190   SELECT CASE P
200   CASE IS<=1
210     LET NX=0:LET NY=.16*Y
220   CASE IS<=8
230     LET NX=.2*X-.26*Y:LET NY=.23*X+.22*Y+1.6
240   CASE IS<=15
250     LET NX=-.15*X+.28*Y:LET NY=.26*X+.24*Y+.44
260   CASE ELSE
270     LET NX=.85*X+.04*Y:LET NY=-.04*X+.85*Y+1.6
280   END SELECT 
290   LET X=NX:LET Y=NY
300   PLOT X*96+600,Y*96
310 NEXT