program kreis;
uses crt, graph;

var gd, gm, i, j           : integer;
    mpx, mpy, x, y, radius : integer;
    winkel                 : real;

procedure bild;
  begin
    mpx:=320; mpy:=240;                      {Center point of rotation}
    radius:=random(100);                     {Radius of circle}
    winkel:=0;                               {Start angle 0}
    for j:=1 to 36 do                        {Full rotation 36 steps a 10ø}
      begin
        winkel:=winkel+10*Pi/180;            {Add 10 degrees each step}
        x:=mpx+round(radius*cos(winkel));    {next middle point of circle}
        y:=mpy-round(radius*sin(winkel));    {with actual angle}
        setcolor(random(15)+1);              {random color(1-15) to draw}
        circle(x, y, radius);                {draw circle}
        delay(100);                          {waiting time}
        if keypressed then exit;             {break with any key}
      end;
    delay(1000);                             {waiting time}
    for j:=1 to 360 do                       {same with 1 degree steps}
      begin
        winkel:=winkel+1*Pi/180;
        x:=mpx+round(radius*cos(winkel));
        y:=mpy-round(radius*sin(winkel));
        setcolor(random(15)+1);
        circle(x, y, radius);
        delay(20);                           {smaller wating time}
        if keypressed then exit;
      end;
    delay(1000);                             {waiting time in ms}
  end;

begin
  gd:=9; gm:=2;                              {Graphic mode 640x480x16 colors}
  randomize;                                 {init random generator}
  initgraph(gd, gm, 'd:\tp\bgi');            {load graphic driver}
  cleardevice;                               {clear screen}
  repeat
    bild;                                    {draw rotationg circle}
    cleardevice;                             {clear screen}
  until keypressed;                          {end with any key}
  cleardevice;                               {clear screen}
  closegraph;                                {back to text mode}
end.
