langton.py

created by nicolas-patrois

created on April 25, 2018

289 Bytes

La fourmi de Langton, n est le nombre de pas de la fourmi.


import kandinsky
def langton(n):
 d=0
 x,y=159,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  if kandinsky.get_pixel(x,y):
   d-=1
   kandinsky.set_pixel(x,y,0)
  else:
   d+=1
   kandinsky.set_pixel(x,y,0xffffff)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222