RosettaCodeData/Task/Langtons-ant/Zkl/langtons-ant.zkl
2017-09-25 22:28:19 +02:00

15 lines
525 B
Text

white:=0xff|ff|ff; black:=0;
w:=h:=100; bitmap:=PPM(w,h,white);
x:=w/2; y:=h/2; dir:=0; // start in middle facing east
do{
if(bitmap[x,y]){ dir-=1; bitmap[x,y]=black; } // white-->black, turn left
else { dir+=1; bitmap[x,y]=white; } // black-->white, turn right
switch(dir.bitAnd(3)){ // dir is always <0
case(0){ x+=1; } // east
case(1){ y-=1; } // south
case(2){ x-=1; } // west
case(3){ y+=1; } // north
}
}while((0<=x<w) and (0<=y<h));
bitmap.write(File("foo.ppm","wb"));