program picdistortion;

uses crush13h,crt;

var x,y,x1,y1,a,counter,add,value1,value2:integer;
    func1,func2,func3,func4:integer;
    c:char;

begin
     video_mode ( $13);
     initvirt;
     inittables;

     cls (0,vp[1]);
     cls (0,vp[2]);
     cls (0,vga);

     loadpcx ('ps-00000.pcx',vp[2]);

     counter:=0;
     add:=10;


     repeat

      counter:=counter+add;
      if counter>1279 then counter:=counter-1279;

      for x:=-160 to 160 do
       for y:=-100 to 100 do
           begin

                value1:=(counter);
                value2:=(counter);
                if value1>1279 then repeat value1:=value1-1279 until value1<1279;
                if value1<0 then repeat value1:=value1+1279 until value1>0;
                if value2>1279 then repeat value2:=value2-1279 until value2<1279;
                if value2<0 then repeat value2:=value2+1279 until value2>0;

                {func1:=round(x*cosines^[value1]-y*sines^[value1]);
                func2:=round(y*cosines^[value1]+x*sines^[value1]);}
                func1:=round(sines^[value1]*4);
                func2:=round(cosines^[value2]*4);

                x1:=round(x*func1+func1);
                y1:=round(y*func2+func2);
                if x1<-159 then repeat x1:=x1+319 until x1>-159;;
                if x1>159 then repeat x1:=x1-319 until x1<159;
                if y1<-99 then repeat y1:=y1+199 until y1>-99;
                if y1>99 then repeat y1:=y1-199 until y1<99;

                mem[vp[1]:(160-x)+(100+y)*320]:=mem[vp[2]:(160-x1)+(100+y1)*320];
           end;

      move(mem[vp[1]:0],mem[vga:0],64000);

      if keypressed=true then c:=readkey;
     until c=#27;

     cleartables;
     closevirt;
     video_mode ( 03);
end.