Cellular automata and image manipulation

D

defcon8

Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.
 
R

Robert Kern

Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.

Why don't you explain your problems with installing numpy (the Numeric Tutorial
is out of date; don't bother with NumTut) or matplotlib on the appropriate
mailing lists?

http://lists.sourceforge.net/lists/listinfo/numpy-discussion
http://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
J

John Bauman

Hello. I have recently been experimenting with cellular automata and I
would like to know how I could convert a 2d list of 0's and 1's into
white and black squares on an image. I have tried to install matplotlib
and also NumTut but both to no avail. There seem to be bugs in their
installation and I have not been able to figure out how to resolve
them. I would be happy for someone to suggest a library and maybe give
a simple example of how to do what I want to do.
In my 1d cellular automaton, I used the python image library and
import Image
nim = Image.new("1", (height * 2, height))
nim.putdata(bimg)
nim.resize((400,200)).save("output.png")

where bimg is a 2d list of 0's and 1's. You could probably remove the
resize.
 
D

defcon8

import Image
x = []
buff = []

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

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


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

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

That is my code. Could you tell me what maybe is wrong? Rule2 makes the
fibonacci triangle btw.
 
D

defcon8

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[0][(len(buff[0])-1)/2] = 1
def rule1():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
if buff[j-1] == 1:
buff[i+1][j] = 1
elif buff[j-1] == 1:
buff[i+1][j] = 1
elif buff[j+1] == 1:
buff[i+1][j] = 1

def rule2():
for i in range(len(buff)-1):
for j in range(len(buff[0])-1):
if i == len(buff)-1:
break
elif j == 0:
if buff[j+1] == 1:
buff[i+1][j] = 1
elif j == len(buff[0])-1:
buff[i+1][j] = 1
elif buff[j-1] == 1 and buff[j+1] != 1:
buff[i+1][j] = 1
elif buff[j+1] == 1 and buff[j-1] != 1:
buff[i+1][j] = 1
elif buff[len(buff[0])-1] == 1 or buff[0] == 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
 
D

defcon8

Actually never mind either. I guessed I needed to append all values
after eachother in one row list:
x = []
for y in buff:
for z in y:
x.append(z)

thanks for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top