program circlefidling;

uses crush13h,crt;

var x,y:integer;
    count1,add1:integer;
    count2,add2:integer;
    c:char;

procedure circles (x,y,n,r,c1:integer;where:word);
var b:integer;
begin
     for b:=1 to r*n do
         begin
              circle(x,y,b,c1*(b div r),where);
         end;
end;

Procedure rotatepal;
var a:integer;
    r,g,b,d,e,f:byte;
begin
     getcolor (255,d,e,f);
     for a:=254 downto 0 do
         begin
              getcolor (a,r,g,b);
              setcolor (a+1,r,g,b);
         end;
     setcolor (0,d,e,f);
end;


begin
     video_mode ( $13);
     initvirt;
     inittables;
     loadpcx ('..\skyscape\cloud2.pcx',vp[1]);

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

     circles (160,100,8,20,20,vp[1]);
     circles (161,100,8,20,20,vp[1]);

     circles (160,100,40,5,7,vp[2]);
     circles (161,100,40,5,7,vp[2]);

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

     count1:=0;
     add1:=10;

     count2:=0;
     add2:=4;

     repeat

     count1:=count1+add1;
     if count1>1799 then count1:=count1-1259;

     count2:=count2+add2;
     if count2>1799 then count2:=count2-1259;

     for y:=-50 to 50 do
         begin
              for x:=-80 to 80 do
                  begin
                       mem[vga:320*round(100-y)+round(160+x)]:=
                       mem[vp[1]:320*round(100-(Y*Cosines^[count1]-X*Sines^[count1])*Cosines^[count2])+
                                     round(160+(X*Cosines^[count1]+Y*Sines^[count1])*sines^[count2])]+
                       mem[vp[2]:320*round(100-y*cosines^[count2])+round(160+x*cosines^[count2]*sines^[count2])];

                  end;
         end;

     {rotatepal;}

     waitvbl;


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

     cleartables;
     closevirt;
     video_mode ( 03);
end.