program ameisen;
uses crt, graph;

var aktfarbe     : byte;
    x, y, gd, gm : integer;
    winkel       : real;

begin
  gd:=9; gm:=2;
  initgraph(gd, gm, 'd:\tp\bgi');
  for y:=0 to 479 do
    for x:=0 to 639 do
      putpixel(x, y, 15);
  randomize;
  x:=random(640);
  y:=random(480);
  winkel:=0;
  repeat
    x:=x+round(cos(winkel));
    y:=y+round(sin(winkel));
    if x<0 then x:=639+x;
    if x>639 then x:=x-639;
    if y<0 then y:=479+y;
    if y>479 then y:=y-479;
    if getpixel(x, y)=15
      then begin
        aktfarbe:=random(9);
        putpixel(x, y, aktfarbe);
        winkel:=winkel-Pi/2;
      end
      else begin
        putpixel(x, y, 15);
        aktfarbe:=getpixel(x, y);
        winkel:=winkel+Pi/2;
      end;
  until keypressed;
  closegraph;
end.