program blurtest;

uses crush13h,crt;

type pos= record
                c:integer;
                x,y,x1,y1:real;
                end;

var position: array [0..50] of pos;
    sc1,sc2:word;
    a,aa,count: integer;
    c: char;

procedure blur(from,too:word);
var x,y,x1,y1,aaa,ccc,counter:integer;
    cccc: array [1..9] of integer;
begin
     for x:=0 to 320 do for y:=0 to 200 do
         begin
          cccc[1]:=mem[from:(x+1)+(y+1)*320];
          cccc[2]:=mem[from:(x)+(y+1)*320];
          cccc[3]:=mem[from:(x-1)+(y+1)*320];
          cccc[4]:=mem[from:(x+1)+(y)*320];
          cccc[5]:=mem[from:(x)+(y)*320];
          cccc[6]:=mem[from:(x-1)+(y)*320];
          cccc[7]:=mem[from:(x+1)+(y-1)*320];
          cccc[8]:=mem[from:(x)+(y-1)*320];
          cccc[9]:=mem[from:(x-1)+(y-1)*320];
          ccc:=0;
          counter:=0;
          for aaa:=1 to 9 do
              begin
                   {if cccc[aaa]<>0 then
                      begin}
                           counter:=counter+1;
                           ccc:=ccc+cccc[aaa];
                     { end;  }
              end;
          if ccc>0 then mem[too:x+y*320]:=round(ccc div counter);
      end;
end;

procedure putball (x,y,col:integer;where:word);
var aaa:integer;
begin
     for aaa:=-2 to 2 do mem[where:(x+aaa)+(y-5)*320]:={mem[where:(x+aaa)+(y-5)*320]+}col;
     for aaa:=-3 to 3 do mem[where:(x+aaa)+(y-4)*320]:={mem[where:(x+aaa)+(y-4)*320]+}col;
     for aaa:=-4 to 4 do mem[where:(x+aaa)+(y-3)*320]:={mem[where:(x+aaa)+(y-3)*320]+}col;
     for aaa:=-5 to 5 do mem[where:(x+aaa)+(y-2)*320]:={mem[where:(x+aaa)+(y-2)*320]+}col;
     for aaa:=-5 to 5 do mem[where:(x+aaa)+(y-1)*320]:={mem[where:(x+aaa)+(y-1)*320]+}col;
     for aaa:=-5 to 5 do mem[where:(x+aaa)+(y)*320]:={mem[where:(x+aaa)+(y)*320]+}col;
     for aaa:=-5 to 5 do mem[where:(x+aaa)+(y+1)*320]:={mem[where:(x+aaa)+(y+1)*320]+}col;
     for aaa:=-5 to 5 do mem[where:(x+aaa)+(y+2)*320]:={mem[where:(x+aaa)+(y+2)*320]+}col;
     for aaa:=-4 to 4 do mem[where:(x+aaa)+(y+3)*320]:={mem[where:(x+aaa)+(y+3)*320]+}col;
     for aaa:=-3 to 3 do mem[where:(x+aaa)+(y+4)*320]:={mem[where:(x+aaa)+(y+4)*320]+}col;
     for aaa:=-2 to 2 do mem[where:(x+aaa)+(y+5)*320]:={mem[where:(x+aaa)+(y+5)*320]+}col;
end;

begin
     video_mode ( $13);
     initvirt;

     randomize;
     c:=' ';
     for a:=0 to 255 do setcolor (a div 16,a div 4, a div 4, a div 4);
     cls (0,vp[2]);
     cls (0,vp[1]);

     for a:=0 to 50 do
         begin
              position[a].x:=random(320)-160;
              position[a].y:=random(200)-100;
              position[a].x1:=(random(11)/10)*random(3)-1 ;
              position[a].y1:=(random(11)/10)*random(3)-1 ;
              position[a].c:=15;
         end;

     count:=0;

     repeat
           count:=count+1;
           if count>round(3.1415926535*40) then count:=0;
           for a:=0 to 50 do
               begin
                    {position[a].x:=position[a].x+position[a].x1;
                    if position[a].x>160 then position[a].x:=-160;
                    if position[a].x<-160 then position[a].x:=160;

                    position[a].y:=position[a].y+position[a].y1;
                    if position[a].y>100 then position[a].y:=-100;
                    if position[a].y<-100 then position[a].y:=100;}

{                    position[a].x:=5*a*cos(count/10);
                    position[a].y:=5*a*sin(count/10);}

                    {position[a].x:=5*a*cos(count/10);
                    position[a].y:=5*a*sin(count/5);}

                    {position[a].x:=a*cos(count/10);
                    position[a].y:=5*a*sin(count/10);}

{                    position[a].x:=5*a*cos(count/10)*cos(count/5);
                    position[a].y:=5*a*sin(count/10)*cos(count/5);}

{                    position[a].x:=5*a*cos(count/10)*sin(a);
                    position[a].y:=5*a*sin(count/10)*cos(a);}

                    position[a].x:=2*a*sin(a)*cos(count/10);
                    position[a].y:=2*a*cos(a)*sin(count/10);

{                    position[a].x:=2*a*sin(a)+sin(count)*5;
                    position[a].y:=2*a*cos(a)+cos(count)*5;}


               end;

{          for a:=0 to 10 do
               begin}
               for aa:=0 to 50 do putball(160+round(position[aa].x),100-round(position[aa].y),position[aa].c,vp[2]);

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

{               end;  }
               for a:=0 to 319 do for aa:=0 to 199 do mem[vga:a+aa*320]:=mem[vp[1]:a +aa*320];

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

     closevirt;
     video_mode ( 03);
end.