program  worm;
{
  Program: RandomWalk
  Author:  (C) GPL Mohsin Ahmed
  Date:    13/Nov/1986
}

{$Igraphlib.pas}
        const   mq = 4;
        type    queueobj =  record
                               x1,y1,x2,y2 : real;
                            end;
{$Iqueue1.lib}
        var     step                      : real;
                i,pdi,pdj                 : integer;
                flag                      : boolean;
                lineone,linetwo                     : queueobj;
begin
      hires;
      randomize;
      queueinit;
      setwindow(-100,-100,100,100);
      setviewport(1,1,80,25);
      useviewport;
      step:=3;
      pdi:=1;
      pdj:=1;
      with lineone do
          begin
          x1:=0;y1:=0;x2:=0;y2:=0;
          end;
      for i:= 1 to 30 do
          flag:=addqueue(lineone);
      repeat
            with lineone do
                 begin
                 x2:=x1+(random(4)-1)*pdi*step;
                 y2:=y1+(random(4)-1)*pdj*step;
                 drawline(x1,y1,x2,y2,white);
                 end;
            flag:=addqueue(lineone);
            with lineone do
                 begin

                if x2>100 then
                   pdi:=-1
                else if x2<-100 then
                   pdi:=1;
                case random(100) of
                    1 : pdi:=random(3)-1;
                    2 : pdj:=random(3)-1;
                end;

                if y2>100 then
                   pdj:=-1
                 else if y2<-100 then
                   pdj:=1;

                 x1 := x2;
                 y1 := y2;
                 end;
                 flag:=delqueue(linetwo);
            with linetwo do
                drawline(x1,y1,x2,y2,black);

            until keypressed ;
end.

