open window 640,512
ss=20

dim sang1(ss)
dim xx(ss)
dim yy(ss)

pi=3.141592653579793/180.0
Counter=0

xpos=320
ypos=500

setrgb 0,255,255,255

repeat
 clear window

 B$=""
 A$=""
 A0$=""
 A1$=""

 st=0
 Gen=mod(Counter,13)+1
 Counter=Counter+1

 if (Gen=1) then
  k=6:s=1.5:ang1=8.0
  A$="0":A1$="11":A0$="1##10!+0!-0"
 fi

 if (Gen=2) then
  k=6:s=1.5:ang1=8.0
  A$="0":A1$="11":A0$="1#+0!1#-0!0"
 fi

 if (Gen=3) then
  k=5:s=3.0:ang1=16.0
  A$="1":A1$="11-#-1+0+0!+#+1-0-0!":A0$="0"
 fi

 if (Gen=4) then
  k=5:s=3.0:ang1=10.0
  A$="1":A1$="1#+0!#=0!1#+1+-0!#-1-+0!":A0$="0-0++0"
 fi

 if (Gen=5) then
  k=5:s=3.0:ang1=16.0
  A$="1":A1$="11-#-1+0+0!+#+1-0-0!":A0$="#0-0++0!"
 fi

 if (Gen=6) then
  k=4:s=2.5:ang1=10.0
  A$="1":A1$="1#+10!1#-10!1":A0$="#0-0++0!"
 fi

 if (Gen=7) then
  k=4:s=1.75:ang1=10.0
  A$="1":A1$="1#+1-10!1#-1+10!10":A0$="#0-0++0!"
 fi

 if (Gen=8) then
  k=4:s=3.0:ang1=10.0
  A$="1":A1$="11#+1-1+10!#-1+1-10!":A0$="#0-0++0!"
 fi

 if (Gen=9) then
  k=4:s=3.5:ang1=10.0
  A$="1":A1$="11#+1+1-#0-0++0!!0#-1-1+#0-0++0!!":A0$="#0-0++0!"
 fi

 if (Gen=10) then
  k=4:s=3.6:ang1=10.0
  A$="#+1-1!#-1+1!":A1$="1#-1+0!1#+1-0!0":A0$="#0-0++0!"
 fi

 if (Gen=11) then
  k=3:s=2.75:ang1=8.0
  A$="1":A1$="11#+10-10+10-10!1#-10+10-10+10!0":A0$="0"
 fi

 if (Gen=12) then
  k=3:s=4.0:ang1=20.0
  A$="1":A1$="1#-10-10-10!1#+10+10+10!1#10!":A0$="0"
 fi

 if (Gen=13) then
  k=4:s=2.0:ang1=8.0
  A$="0":A1$="111":A0$="11#+0!#++0!#+++0!#-0!#--0!#---0!0"
 fi

' String Generator

 for Frw=1 to k
  cl=len(A$)
  for i=1 to cl
   if (mid$(A$,i,1)="1") then
    B$=B$+A1$
   elsif (mid$(A$,i,1)="0") then
    B$=B$+A0$
   else
    B$=B$+mid$(A$,i,1)
   fi
  next i

  A$=B$
  B$=""

  ang=360.0/ang1:
  x=0:
  y=0:
  an=0:
  cl=len(A$)
  for i=1 to cl
   if (mid$(A$,i,1)="1") then
    ran1=ran()
    ran2=ran()
    s2=s+0.5*(ran1-ran2)*s
    ran1=ran()
    ran2=ran()
    an=an+5.0*(ran1-ran2)
    sang=an
    x1=s2*sin(an*pi)+x
    y1=s2*cos(an*pi)+y
    xp=2*x+xpos
    yp=ypos-2*y
    xp1=2*x1+xpos
    yp1=ypos-2*y1
    setrgb 1,0,192,0
    line xp,yp to xp1,yp1
    x=x1
    y=y1
   elsif (mid$(A$,i,1)="0") then
    zx=sin(an*pi)
    zy=cos(an*pi)
    x1=zx*s+x
    y1=zy*s+y
    xp=2*x+xpos
    yp=ypos-2*y
    xp1=2*x1+xpos
    yp1=ypos-2*y1
    setrgb 1,255,128,0
    line xp,yp to xp1,yp1
    x1=0.25*zx*s+x
    y1=0.25*zy*s+y
    xp1=2*x1+xpos
    yps=ypos-2*y1
    setrgb 1,255,0,0
    line xp,yp to xp1,yp1
   elsif (mid$(A$,i,1)="-") then
    ran1=ran()
    ran2=ran()
    an=an-ang-10.0*(ran1-ran2)
    sang=an
   elsif (mid$(A$,i,1)="+") then
    ran1=ran()
    ran2=ran()
    an=an+ang+10*(ran1-ran2)
    sang=an
   elsif (mid$(A$,i,1)="#") then
    st=st+1
    sang1(st)=sang
    xx(st)=x
    yy(st)=y
   elsif (mid$(A$,i,1)="!") then
    x=xx(st)
    y=yy(st)
    an=sang1(st)
    sang=an
    st=st-1
   fi
  next i
 next Frw
until (0=1)


