Explicar paso a paso este programa
Publicado por rfr2000 (12 intervenciones) el 07/01/2013 11:52:08
Por favor me podéis explicar paso a paso este programa?
uses
crt;
procedure linea(x, y, x2, y2 : integer);
var
z, dx, dy, ap, bp, xe, ye : integer;
begin
if x < x2 then
begin
xe := 1;
dx := x2 - x;
end
else
begin
xe := - 1;
dx := x - x2;
end;
if y < y2 then
begin
ye := 1;
dy := y2 - y;
end
else
begin
ye := - 1;
dy := y - y2;
end;
gotoxy(x,y);write('.');
if dx > dy then
begin
ap := (dy - dx) * 2;
bp := dy * 2;
z := bp - dx;
repeat
if z >= 0 then
begin
inc(y,ye);
inc(z,ap);
end
else
inc(z,bp);
inc(x,xe);
gotoxy(x,y);write('.');
until x = x2;
end
else
begin
ap := (dx - dy) * 2;
bp := dx * 2;
z := bp - dy;
repeat
if z >= 0 then
begin
inc(x,xe);
inc(z,ap);
end
else
inc(z,bp);
inc(y,ye);
gotoxy(x,y);write('.');
until y = y2;
end;
end;
begin
clrscr;
linea(30,10,50,10);
linea(30,10,40,20);
linea(50,10,40,20);
linea(30,17,50,17);
linea(30,17,40,7);
linea(50,17,40,7);
readln;
end.
uses
crt;
procedure linea(x, y, x2, y2 : integer);
var
z, dx, dy, ap, bp, xe, ye : integer;
begin
if x < x2 then
begin
xe := 1;
dx := x2 - x;
end
else
begin
xe := - 1;
dx := x - x2;
end;
if y < y2 then
begin
ye := 1;
dy := y2 - y;
end
else
begin
ye := - 1;
dy := y - y2;
end;
gotoxy(x,y);write('.');
if dx > dy then
begin
ap := (dy - dx) * 2;
bp := dy * 2;
z := bp - dx;
repeat
if z >= 0 then
begin
inc(y,ye);
inc(z,ap);
end
else
inc(z,bp);
inc(x,xe);
gotoxy(x,y);write('.');
until x = x2;
end
else
begin
ap := (dx - dy) * 2;
bp := dx * 2;
z := bp - dy;
repeat
if z >= 0 then
begin
inc(x,xe);
inc(z,ap);
end
else
inc(z,bp);
inc(y,ye);
gotoxy(x,y);write('.');
until y = y2;
end;
end;
begin
clrscr;
linea(30,10,50,10);
linea(30,10,40,20);
linea(50,10,40,20);
linea(30,17,50,17);
linea(30,17,40,7);
linea(50,17,40,7);
readln;
end.
Valora esta pregunta


0