program liniendrehen;                        {rotationg lines, one centre}
uses crt, graph;

var gd, gm, ix, iy, x1, x2, y1, y2, l : integer;


procedure bild;
                                             {Draw line with precalculated}
  begin                                      {start and end}
    line(x1+ix, y1+iy, x2-ix, y2-iy);
    if (x1+ix)<=(x2-ix) then inc(iy, 2);     {From 0-89ø left end down 2}
    if (x1+ix)>(x2-ix) then dec(iy, 2);      {From 90-170ø left end up 2}
    inc(ix, 2);                              {Left end always right 2}
                                             {Right end the opposite}
    delay(50);                              {Waiting time}
  end;

begin
  randomize;                                 {Init random generator}
  ix:=0; iy:=0;                              {Init rotating add-values}
  x1:=random(480);                           {Start point of line}
  y1:=random(280)+100;
  l:=random(100)+100;                        {Length of line}
  x2:=l+x1;                                  {End point of line}
  y2:=y1;
  detectgraph(gd, gm);
  initgraph(gd, gm, 'd:\tp\bgi');            {Load graphic driver}
  setcolor(random(15)+1);                    {Set random draw color}
  repeat
    bild;                                    {Draw 1 rotating line}
    if iy=0 then                             {When finished one rotation}
      begin
        setcolor(random(15)+1);              {Next color, start, end, length}
        {cleardevice;}                       {for a new line}
        ix:=0; iy:=0;
        x1:=random(480);
        l:=random(100)+100;
        x2:=l+x1;
        y1:=random(480);
        y2:=y1;
        delay(500);                          {Waiting time}
      end;
  until keypressed;                          {End with any key}
  closegraph;                                {Back to textmode}
end.
