# Cellular automata and image manipulation

defcon8 defcon8 at gmail.com
Sun May 14 10:52:45 CEST 2006

```Sorry this is the latest, the previous didn't work so well:

import Image
x = []
buff = []

buff = [[0 for y in range(41)] for x in range(21)]
buff[(len(buff)-1)/2] = 1
def rule1():
for i in range(len(buff)-1):
for j in range(len(buff)-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff)-1:
if buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1:
buff[i+1][j] = 1

def rule2():
for i in range(len(buff)-1):
for j in range(len(buff)-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[i][j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff)-1:
buff[i+1][j] = 1
elif buff[i][j-1] == 1 and buff[i][j+1] != 1:
buff[i+1][j] = 1
elif buff[i][j+1] == 1 and buff[i][j-1] != 1:
buff[i+1][j] = 1
elif buff[i][len(buff)-1] == 1 or buff[i]  == 1:
break

rule2()
nim = Image.new("1", (50,50))
nim.putdata(buff)
nim.resize((400,600)).save("output.png")

for a in buff:
for x in a:
if x == 1:
print "X",
elif x == 0: print " ",
print ""

for a in buff:
print a

```

More information about the Python-list mailing list