Pascal/Turbo Pascal - Explicar paso a paso este programa

 
Vista:

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.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Explicar paso a paso este programa

Publicado por ramon (2158 intervenciones) el 07/01/2013 19:34:49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{Espero esto te ayude}
 
uses
    crt;
    {Esto es el algoritmo de Linea Bresenham}
 
 
  procedure linea(x, y, x2, y2 : integer); {cordenadas de la linea}
  var
     z, dx, dy, ap, bp, xe, ye : integer; {variables locales}
     begin
     if x < x2 then {comprovacion de cordenadas para decidir forma x}
     begin
       xe := 1;  {si x menor x2 entoncas esta forma}
       dx := x2 - x;
     end
  else
     begin
       xe := - 1;  {si no esta otra}
       dx := x - x2;
    end;
   if y < y2 then  {comprovacion de cordenadas para decidir forma y}
   begin
      ye := 1;    {si y menor y2 entoncas esta forma}
      dy := y2 - y;
   end
 else
     begin
        ye := - 1;  {si no esta otra}
        dy := y - y2;
     end;
     gotoxy(x,y);write('.'); {primer punto a partir de este dependiendo de
                              los datos tomados sera }
     if dx > dy then     {si dx mayor dy realizamos esto}
      begin
         ap := (dy - dx) * 2; {tomamos incremento para z en eje y}
         bp := dy * 2;    {tomamos incremento para z en eje x}
         z := bp - dx; {inicio del valor z}
    repeat     {repetimos asta x sea igual a x2 longitud entrada}
        if z >= 0 then  {mientras z sea mayor o igual a cero acemos 1 y 2
                         sino 3 y 2}
        begin
          inc(y,ye); {1}
          inc(z,ap); {1}
        end
    else
        inc(z,bp); {3}
        inc(x,xe); {2}
        gotoxy(x,y);write('.'); {y ponemos punto}
    until x = x2;   {termina cuando son igual}
    end
  else     {si dx > dy entonces esto}
     begin
        ap := (dx - dy) * 2;  {tomamos incremento para z en eje x}
        bp := dx * 2;    {tomamos incremento para z en eje y}
        z := bp - dy;  {inicio del valor z}
     repeat    {repetimos asta y sea igual a y2 longitud entrada}
        if z >= 0 then  {si z mayor o igual 0 entonces 1/2/3 sino 4/3}
        begin
           inc(x,xe);{1}
           inc(z,ap);{2}
        end
    else
        inc(z,bp); {4}
        inc(y,ye); {3}
        gotoxy(x,y);write('.'); {y ponemos punto}
    until y = y2;   {termina cuando son igual}
    end;
  end;
 
  begin
     clrscr;  {limpia pantalla}
     linea(30,10,50,10); {linea horizontal superior}
     linea(30,10,40,20); {linea inclinada I/D}
     linea(50,10,40,20); {linea inclinada D/I}
     linea(30,17,50,17); {linea horizontal inferior}
     linea(30,17,40,7);  {linea inclinada I/D}
     linea(50,17,40,7);  {linea inclinada D/I}
     readln;    {pausa asta pulsar enter}
    end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Explicar paso a paso este programa

Publicado por rfr2000 (12 intervenciones) el 08/01/2013 17:59:27
Muchas gracias y un saludo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar