program farben2;
uses Graph, crt, farbwahl;

var Driver, Mode, i : Integer;
    x, y, j, k, l : integer;
    istr : string[2];

begin
  randomize;                                 {Init random generator}
  Driver := detect;
  Mode := detect;
  InitGraph(Driver, Mode, 'd:\tp\bgi');      {Load graphic driver}
  if GraphResult < 0 then Halt(1);           {If load error then end}
  setbkcolor(0);                             {Background color black}
  x:=0;
  y:=0;
  l:=1;                                      {Start color}
  repeat
    zufallfarbe(l);                          {Random RGB for color l}
    if l<15 then inc(l) else l:=1;           {Next color (1..15)}
    setfillstyle(1, l);                      {Color for filling}
    setcolor(0);                             {Draw color black}
    pieslice(random(639), random(479), 0, 360, 10);
                                             {Draw filled circle on
                                              random place}
    delay(50);                               {Waiting time in ms (nearly)}
  until keypressed;                          {End with any key}
  for I:=0 to 15 do resetcolor(i);           {Reload standard RGBs for colors}
  closegraph;                                {Back to text mode}
end.
