uses screen, memory, crt, dos;

const
VGA=$a000;

Procedure FillCircleSQRT(x0,y0: word; buf1,buf2:word);
var
x,y:integer;
r:single;
u,v:byte;
begin
    for y:=0 to 199 do
     for x:=0 to 319 do
       begin
          r:=sqrt((y-y0)*(y-y0)+(x-x0)*(x-x0));
          v:= ((X-x0)*64) div round(192-r);
          u:= ((Y-y0)*64) div round(192-r);{}
          if y<100 then memw[buf1:word((x+y*320) shl 1)]:=v+u*256
          else memw[buf2:word((x+(y-100)*320) shl 1)]:=v+u*256;
       end;
end;


Procedure FillCircleSQRT2(x0,y0: word; buf1,buf2:word);
var
x,y:integer;
a:single;
r:single;
color,u,v:byte;
begin
    for y:=0 to 199 do
     for x:=0 to 319 do
       begin
          if (x-x0>0) and (y-y0>=0) then a:=arctan((y-y0) / (x-x0));
          if (x-x0>0) and (y-y0<0)  then a:=arctan((y-y0) / (x-x0))+2*pi;
          if (x-x0=0) and (y-y0>=0) then a:=arctan(y-y0);
          if (x-x0=0) and (y-y0<0)  then a:=arctan(y-y0)+2*pi;

          if (x-x0<0) then a:=arctan((y-y0) / (x-x0))+pi;
          a:=a / (2*pi);

          r:=sqrt((y-y0)*(y-y0)+(x-x0)*(x-x0));

          u:=byte(round(a*256));
          {u:=byte(round(u-r*3)); {twirl}
          v:=byte(round(r));

          if y<100 then memw[buf1:word((x+y*320) shl 1)]:=v+u*256
          else memw[buf2:word((x+(y-100)*320) shl 1)]:=v+u*256;
       end;
end;


procedure save_data(name:string; size:longint; from:word);
var fw1:file;
i:word;
begin
Assign(fw1, name);
Rewrite(fw1,1);
Reset(fw1, 1);
for i:=0 to size-1 do BlockWrite(fw1, mem[from:i], 1);
Close(fw1);
end;


var
fw1,fw2:file;

c, i, x,y,n,m,yy,xx:word;
fr:file;
col, r,g,b:byte;
size:word;

begin
SetUpVirtual(scr,vaddr);
SetUpVirtual(scr2, vaddr2);
SetUpVirtual(scr3, vaddr3);

    FillCircleSQRT(160,99,vaddr2,vaddr3);
    save_data('cred2_1.bin', 64000, vaddr2);
    save_data('cred3_1.bin', 64000, vaddr3);

    FillCircleSQRT2(160,99,vaddr2,vaddr3);
    save_data('cred2_2.bin', 64000, vaddr2);
    save_data('cred3_2.bin', 64000, vaddr3);

   WriteLn('Done');


readkey;


end.