Dim Sn(20)
In:
Cls
Print "Enter an even number of cycles (2-20)"
Input "or enter a zero to quit: ";Nc$
Nc=Val(Nc$)
If Nc=0
  End
Endif
If Nc<2 Or Nc>20
  Goto In
Endif
If Even(Nc)<>-1
  Goto In
Endif
L=128
For C=2 To Nc Step 2
  L=L/2
Next C
X=85
Y=100
Cls
Color 3
Plot X,Y
For C=0 To Nc
  Sn(C)=0
Next C
180:
D=0
For C=1 To Nc
  If Sn(C-1)=Sn(C)
    D=D-1
    Goto 200
  Endif
  D=D+1
  200:
  If D=-1
    D=7
  Endif
  If D=8
    D=0
  Endif
Next C
If D=0
  X=X+L+L
  Goto 270
Endif
If D=2
  Y=Y+L
  Goto 270
Endif
If D=4
  X=X-L-L
  Goto 270
Endif
Y=Y-L
270:
Color 3
Draw  To X,Y
Sn(Nc)=Sn(Nc)+1
For C=Nc To 1 Step -1
  If Sn(C)<>2
    C=1
    Goto 300
  Endif
  Sn(C)=0
  Sn(C-1)=Sn(C-1)+1
  300:
Next C
If Sn(0)=0
  Goto 180
Endif
Print At(7,23);"Press any key to continue"
Repeat
Until Inkey$<>""
Goto In
