program kegel;
uses crt, graph;

var gd, gm, i : integer;

procedure punktstart(x1, y1, x2, y2: integer; var pt: arccoordstype);
  begin
    with pt do                               {Init points in pt}
      begin
        Xstart:=x1; Xend:=x2; Ystart:=y1; Yend:=y2;
      end;
  end;

procedure punktadd(x1, y1, x2, y2 : integer; var pt: arccoordstype);
  begin
    with pt do
      begin                                  {add values to pt-content}
        Xstart:=Xstart+x1; Xend:=Xend+x2;
        Ystart:=Ystart+y1; Yend:=Yend+y2;
      end;
  end;

procedure kegelzeichnen(x, y : integer; ri:byte);

  var pt   : arccoordstype;
      ende : boolean;
      durch, add : byte;

  begin
    durch:=0;                                {init counting lines of cone}
    case ri of                               {direction of the cone}
        0: punktstart(80+y, x, 80+y, x, pt);         {upwards}
        1: punktstart(x, y, x, y, pt);               {left}
        2: punktstart(80+y, 479-x, 80+y, 479-x, pt); {downwards}
        3: punktstart(640-x, y, 640-x, y, pt);       {right}
      end; {of case}
    repeat
      for y:=pt.ystart to pt.yend do         {draw one line of the cone}
        for x:=pt.xstart to pt.xend do       {horizontal or vertical}
          putpixel(x, y, getpixel(x, y)+1);  {on each pixel use next color
                                              of last written on this point}
      inc(durch);                            {count lines of cone}
      add:=0;
      if durch mod 10 = 0 then add:=1;       {cone width+1 each 10 lines}
      case ri of                             {add for each direction}
          0: punktadd(-add, 1, add, 1, pt) ;
          1: punktadd(1, -add, 1, add, pt);
          2: punktadd(-add, -1, add, -1, pt);
          3: punktadd(-1, -add, -1, add, pt);
        end;
      ende:=false;
       if (add=1) then case ri of            {end if screen boundary reached}
          0: ende:=(pt.Ystart>=480);
          1: ende:=(pt.Xstart>=640);
          2: ende:=(pt.Ystart<=0);
          3: ende:=(pt.Xstart<=0);
        end;
    until ende;                              {end when cone finished}
  end;

begin
  randomize;                                 {init random generator}
  gd:=9; gm:=2;
  initgraph(gd, gm , 'd:\tp\bgi');           {load graphic driver}
  repeat
    for i:=1 to 25 do                        {draw 25 cones for full screen}
      kegelzeichnen(random(100), random(480), random(4));
                                             {begin on random places}
  until keypressed;                          {end with any key}
  cleardevice;                               {clear screen}
  closegraph;                                {back to textmode}
end.
