Well, I'm programming Conway's game of life in python, and although my program works, the way the user gives the initial points is writing the coordinates of each point.
I want an interface that shows the points with integer coordinates of the cartesian plane, let me select some with the mouse and finally give back the points I selected as tuples(or lists, doesn't matter). Should I download some kind of program or there is a module that has such functionality?
I would also like to ask for some "program" that instead of points, graphs pixels, like in this video. Right now, I'm just using matplotlib to graph, but I think it looks cooler with pixels.
Thanks in advance. EDIT: I didn't want to post the code, for being so long, but here it is.
import matplotlib.pyplot as plt
from string import split
reglas=raw_input("Enter rule of the game(Ej.:B3/23)")
Q=[letra for letra in reglas]
m=Q.index("/")
born, keep=[int(i) for i in Q[1:m]], [int(i) for i in Q[m+1:]]
discard=[x for x in range(1,9) if x not in keep and x not in born]
livecells=set()
a=raw_input("Enter a coordinate (a,b), which will be a living cell. This program will keep you asking coordinates until you decide to stop. To stop, instead of a coordinate, enter stop")
a=tuple([int(float(i)) for i in split(a)])
livecells.add(a)
while True:
b=raw_input("Another coordinate")
if b!="stop":
b=tuple([int(i) for i in split(b)])
livecells.add(b)
else:
break
def whoisnear(a,b):
return set([(a+1,b),(a+1,b+1),(a+1,b-1),(a,b+1),(a,b-1),(a-1,b+1),(a-1,b),(a-1,b-1)])
def firstcoordinate(x,y):
return x
def secondcoordinate(x,y):
return y
def rectanglearea(c,d,e,f):
candidates=set()
for i in range (c-3,d+3):
for j in range(e-3,f+3):
candidates.add((i,j))
return candidates
Q=[x for (x,y) in livecells]
W=[y for (x,y) in livecells]
plt.plot(Q,W,'ro')
plt.axis([min(Q)-1,max(Q)+1,min(W)-1,max(W)+1])
plt.savefig('0.png')
plt.show()
repetitions=0
minx=min([firstcoordinate(*i) for i in livecells])
maxx=max([firstcoordinate(*i) for i in livecells])
miny=min([secondcoordinate(*i) for i in livecells])
maxy=max([secondcoordinate(*i) for i in livecells])
for j in range(1,30):
try:
X={firstcoordinate(*i) for i in livecells}
Y={secondcoordinate(*i) for i in livecells}
D=rectanglearea(min(X),max(X),min(Y),max(Y))
Todiscard=set()
Toadd=set()
for i in D:
K=whoisnear(*i) & livecells
n=len(K)
if n in discard:
Todiscard.add(i)
elif n in born:
Toadd.add(i)
livecells=livecells-Todiscard
livecells=livecells|Toadd
firstcords=[x for (x,y) in livecells]
secondcords=[y for (x,y) in livecells]
plt.plot(firstcords,secondcords,'ro')
plt.axis([minx-30,maxx+30,miny-30,maxy+30])
plt.savefig(str(j)+'.png')
plt.close()
except ValueError:
print j,livecells
break
This is a script I developed to extend the
pygame
module. I don't want to write your code for you but this should get you started! My code is well documented and should be easy for you to understand. Good luck!Screen Module
Main Code