%control 0
%begin
%include ":l:moose:mouse.inc"
%include ":l:b:inc:region.imp"
%include ":l:ndemo:level1:graphinc.imp"
%include ":l:ndemo:graeme:random.inc"
%include ":l:src:util.imp"

%constinteger no of maps = 13
%constantinteger frame = 16_E00000, colourreg = 16_E20001
%bytearray bitmap(1:no of maps,1:64*64)
%integer i,reference,size
%integer x,y,sign,step,who
%real gradient,ry

%routine wait(%integer msecs)
%integer start

start= realtime
%cycle;%repeatuntil realtime-start >= msecs

%end


%option "-low"
%routine disp(%integer x,y,%bytename line)

%label ok

  *move.l d0,d2
  *lsl.l #7,d1
  *andi.l #16_FFFFFFF0,d0
  *lsr.l #3,d0
  *add.l d0,d1
  *lea   frame,a1
  *lea   0(a1,d1.l),a1
  *move.l a1,a3
  *adda.l #128,a3
  *lea   colourreg,a2
  *andi.l #15,d2
  *eor.l  #15,d2
  *clr.l  d1
  *bset   d2,d1
  *moveq  #63,d3
z:*moveq  #63,d0
a:*move.b (a0)+,(a2)
  *move.w d1,(a1)
  *ror.w #1,d1
  *btst  #15,d1
  *beq   ok
  *lea    2(a1),a1
ok:
  *dbra   d0,a
  *move.l a3,a1
  *adda.l #128,a3
  *bset   d2,d1
  *dbra   d3,z
%end

%routine calc new point

   x=x+step*sign
   ry=ry+ step*gradient
   y=int(ry)
   %if y>=446 %start
      gradient=random real(0.1,0.5) %until gradient # 0
      gradient = -1/gradient
      y=446
      x=0 %if x<0
      x=623 %if x>623
      %return
   %finishelseif y<=0 %start
      gradient=random real(0.1,0.5) %until gradient # 0
      gradient = 1/gradient
      y=0
      x=0 %if x<0
      x=623 %if x>623
      %return
   %finish

   %if x>=623 %or x<=0 %start
      %stopif testsymbol=25
      who = random int(1,no of maps) %untilnot 7 <= who <= 8
!      printstring("It is ->");write(who,0);newline
      step = random int(10,20)
      gradient=random real(0.1,0.5) %until gradient # 0
      gradient = 1/gradient
      sign=-sign
      x=511 %if x>511
      x=0 %if x<0
   %finish

%end

clear
colour map(i)=i<<10!i<<5!i %for i=0,1,31
access file(":l:ndemo:graeme:gallery.dat",0,reference,size)
readregion(reference,0,size,bitmap(1,1))
de access file(reference)

x=0;y=0
initialise random
gradient = random real(0.1,2)
gradient = 1/gradient
step = random int(5,15)
who = random int(1,no of maps) %untilnot 7 <= who <= 8
ry=0
sign=1
%cycle
      disp(x,y,bitmap(who,1))
      calc new point
%repeat
%endofprogram
