procedure Tunnel(cnv: TCanvas;width,height,d:integer;c1,c2,c3:TColor; cp: TPoint);
var
i,a: integer;
alpha,beta,n: real;
// width,height: breite/höhe des tunnels
// d: linienabstand
// c123: farben
// cp: mittelpunkt
procedure cpc(var cnv: TCanvas); // farbe ändern
begin
if cnv.Pen.Color = c1 then
cnv.Pen.Color:=c2
else
cnv.Pen.Color:=c1;
end;
function cpt(x,y: integer): integer; // "strahlensatz"
begin
if x = 0 then result := 0
else result:=round(((x-i)/x)*y);
end;
begin
if cp.X = 0 then cp.X:=1;
if cp.Y = 0 then cp.Y:=1;
with cnv do // ecklinien zeichnen
begin
Brush.Color:=c3;
FillRect(rect(0,0,width,height));
Pen.Color:=c1;
Pen.Width:=2;
MoveTo(0,0);
LineTo(cp.X,cp.Y);
LineTo(width,0);
MoveTo(0,height);
LineTo(cp.X,cp.Y);
LineTo(width,height);
Pen.Width:=1;
end;
// links/rechts linien zum mittelpunkt
i:=0;
cpc(cnv);
while i <= form2.Image1.Height do
begin
cnv.MoveTo(0,i);
cnv.LineTo(cp.X,cp.y);
cnv.LineTo(width,i);
inc(i,d);
end;
// oben/unten linien zum mittelpunkt
i:=0;
cpc(cnv);
while i <= width do
begin
cnv.MoveTo(i,0);
cnv.LineTo(cp.X,cp.y);
cnv.LineTo(i,height);
inc(i,d);
end;
//querlinien
//links
i:=0;
cpc(cnv);
alpha:=arctan(d/cp.X);
beta:=((Pi/2)-alpha)/2;
n:=d;
while i <= cp.X do
begin
cnv.MoveTo(i,cp.Y+cpt(cp.X,height-cp.Y));
cnv.LineTo(i,cp.Y-cpt(cp.X,cp.Y));
a:=round(tan(beta)*n);
if a = 0 then break;
inc(i,a);
n:=tan(alpha)*(cp.X-i);
end;
//rechts
i:=0;
alpha:=arctan(d/(width-cp.X));
beta:=((Pi/2)-alpha)/2;
n:=d;
while i <= width-cp.X do
begin
cnv.MoveTo(width-i,cp.Y+cpt(width-cp.X,height-cp.Y));
cnv.LineTo(width-i,cp.Y-cpt(width-cp.X,cp.Y));
a:=round(tan(beta)*n);
if a = 0 then break;
inc(i,a);
n:=tan(alpha)*((width-cp.X)-i);
end;
//oben
cpc(cnv);
i:=0;
alpha:=arctan(d/cp.Y);
beta:=((Pi/2)-alpha)/2;
n:=d;
while i <= cp.Y do
begin
cnv.MoveTo(cp.X+cpt(cp.Y,width-cp.X),i);
cnv.LineTo(cp.X-cpt(cp.Y,cp.X),i);
a:=round(tan(beta)*n);
if a = 0 then break;
inc(i,a);
n:=tan(alpha)*(cp.Y-i);
end;
//unten
i:=0;
alpha:=arctan(d/(height-cp.Y));
beta:=((Pi/2)-alpha)/2;
n:=d;
while i <= height-cp.Y do
begin
cnv.MoveTo(cp.X+cpt(height-cp.Y,width-cp.X),height-i);
cnv.LineTo(cp.X-cpt(height-cp.Y,cp.X),height-i);
a:=round(tan(beta)*n);
if a = 0 then break;
inc(i,a);
n:=tan(alpha)*((height-cp.Y)-i);
end;
end;