'BARNSLEY FERN

include "sdl.inc"

SetDisplay 640,500, 1
SetCaption "SDL FERN DEMO"

single a, b, c, d, e, f, newx, newy, sys r, wa 
Dim xy(2) as single

Sub Fern
r = Rand(0,100)
iF r <= 10 
   a = 0
   b = 0
   c = 0
   d = 0.16
   e = 0
   f = 0
ElseiF r > 1 and r <=86 
   a = 0.85
   b = 0.04
   c = -.04
   d = 0.85
   e = 0
   f = 1.60
ElseiF r > 86 and r <=93 
   a = 0.2
   b = -.26
   c = 0.23
   d = 0.22
   e = 0
   f = 0.16
Else
   a = -.15
   b = 0.28
   c = 0.26
   d = 0.24
   e = 0
   f = 0.44
End iF
newx = ((a * xy(1)) + (b * xy(2)) + e)
newy = ((c * xy(1)) + (d * xy(2)) + f)
xy(1) = newx
xy(2) = newy 
SetPixel( xy(1)*40+275,xy(2)*40+50, 0,210,55 )
End Sub

ClsColor 28,28,28
wa=0
do
  int i
  for i=1 to 10
    wa++
    if wa=30000 or key(27) then exit do
    Fern
  next
  SetCaption "Fern Points:  " + str(wa)
  Flip
end do
WaitKey(27)
Ends