multilangton.py

created by uncurieux

created on May 01, 2019

2.84 KB

You know the Langton’s ant : there is only two colors. In this script you have Langton’s ant with 3, 4, 5, 7 and 11 colors ! Enjoy to see these creations :)

I used https://workshop.numworks.com/python/nicolas-patrois/langton and https://youtu.be/i8N2xnMm6qE


from kandinsky import *
def langton_3(n):
 d=0
 x,y=160,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,65535)
  elif a==65535:
   d+=1
   set_pixel(x,y,1023)
  elif a==1023:
   d+=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222

def langton_4(n):
 d=0
 x,y=160,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,65535)
  elif a==65535:
   d+=1
   set_pixel(x,y,63488)
  elif a==63488:
   d+=1
   set_pixel(x,y,1023)
  elif a==1023:
   d-=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222

def langton_5(n):
 d=0
 x,y=160,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,65535)
  elif a==65535:
   d-=1
   set_pixel(x,y,63488)
  elif a==63488:
   d-=1
   set_pixel(x,y,1023)
  elif a==1023:
   d+=1
   set_pixel(x,y,65504)
  elif a==65504:
   d-=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222

def langton_7(n):
 d=0
 x,y=280,180
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,65535)
  elif a==65535:
   d-=1
   set_pixel(x,y,63490)
  elif a==63490:
   d-=1
   set_pixel(x,y,2016)
  elif a==2016:
   d+=1
   set_pixel(x,y,63519)
  elif a==63519:
   d-=1
   set_pixel(x,y,64480)
  elif a==64480:
   d+=1
   set_pixel(x,y,1023)
  elif a==1023:
   d-=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222

def langton_11_1(n):
 d=0
 x,y=160,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,65535)
  elif a==65535:
   d+=1
   set_pixel(x,y,63490)
  elif a==63490:
   d-=1
   set_pixel(x,y,2016)
  elif a==2016:
   d-=1
   set_pixel(x,y,63488)
  elif a==63488:
   d-=1
   set_pixel(x,y,63503)
  elif a==63503:
   d-=1
   set_pixel(x,y,63519)
  elif a==63519:
   d+=1
   set_pixel(x,y,30751)
  elif a==30751:
   d+=1
   set_pixel(x,y,31)
  elif a==31:
   d+=1
   set_pixel(x,y,2047)
  elif a==2047:
   d-=1
   set_pixel(x,y,64480)
  elif a==64480:
   d-=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222

def langton_11_2(n):
 d=0
 x,y=160,111
 e=((0,1),(-1,0),(0,-1),(1,0))
 for _ in range(n):
  a=get_pixel(x,y)
  if a==0:
   d-=1
   set_pixel(x,y,2031)
  elif a==2031:
   d+=1
   set_pixel(x,y,65535)
  elif a==65535:
   d-=1
   set_pixel(x,y,2016)
  elif a==2016:
   d-=1
   set_pixel(x,y,63488)
  elif a==63488:
   d-=1
   set_pixel(x,y,63503)
  elif a==63503:
   d-=1
   set_pixel(x,y,63519)
  elif a==63519:
   d+=1
   set_pixel(x,y,30751)
  elif a==30751:
   d+=1
   set_pixel(x,y,31)
  elif a==31:
   d+=1
   set_pixel(x,y,2047)
  elif a==2047:
   d-=1
   set_pixel(x,y,64480)
  elif a==64480:
   d-=1
   set_pixel(x,y,0)
  d%=4
  x+=e[d][0]
  y+=e[d][1]
  x%=320
  y%=222