uses memory,crt;
const
hexoid :array[0..4*6-1] of shortint =(
-3, -5,   -3, 5,   -6, 0,
-3, -5,    3, 5,   -3, 5,
-3, -5,    3,-5,    3, 5,
 3, -5,    6, 0,    3, 5);



procedure hex(xx,yy:integer; size:single; p,  where:word);
var
x,y:array[0..2] of integer;
n,m:word;
begin
  for m:=0 to 3 do begin
     for n:=0 to 2 do begin
         x[n]:=round(hexoid[n*2   +m*6]   * size) +xx;
         y[n]:=round(hexoid[n*2+1 +m*6]   * size) +yy;
     end;
     {Triangle_asm(x[0],y[0], x[1],y[1], x[2],y[2], col, vaddr);}
     memw[where:p*48+  m*12   ]   :=word(x[0]);
     memw[where:p*48+  m*12+2 ]   :=word(y[0]);
     memw[where:p*48+  m*12+4 ]   :=word(x[1]);
     memw[where:p*48+  m*12+6 ]   :=word(y[1]);
     memw[where:p*48+  m*12+8 ]   :=word(x[2]);
     memw[where:p*48+  m*12+10]   :=word(y[2]);
  end;
end;


function make_mesh_hexboard(v,h:integer; size, border:single; xx,y:integer; where:word):word;
var m,n,x:integer;
p:word;
begin
p:=0;
for m:=0 to v do begin
    for n:=0 to h do begin
      x:=round(n*(12*size *1.5)) +xx;
      hex(x,y, size-border, p, where);
      inc(p);
    end;

    y:=y+round(  (10*size *0.5));
    for n:=0 to h do begin
      x:=round((n+0.5)*(12*size *1.5)) +xx;
      hex(x,y, size-border, p, where);
      inc(p);
    end;
    y:=y+round(  (10*size *0.5));
end;
make_mesh_hexboard:=p;
end;



var
 i, num_triangles, num_hexagons, n,m:word;
 complete, active_p, col:byte;
 b, size:single;
 h,v, xx,yy,x,y:integer;
 fw1:file;


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



size:=8;
y:=0;
b:=1;

v:=4; h:=4;

xx:= -320;
yy:=0;

num_hexagons:=make_mesh_hexboard(v,h, size, b, xx,yy, vaddr2);

Assign(fw1, 'hexmesh.bin');
Rewrite(fw1,1);
Reset(fw1, 1);
for i:=0 to num_hexagons*(12*4)-1 do BlockWrite(fw1, mem[vaddr2:i], 1);
Close(fw1);

WriteLn(num_hexagons,' hexagons. ',i+1, ' byte save complete');
readkey;
repeat until keypressed;




end.