나는 삶의 구현 콘웨이의 게임이 : 나는 결과를 시각화 할matplotlib로 포인트 세트를 어떻게 애니메이트 할 수 있습니까?
def neighbors(point):
x, y = point
for i, j in itertools.product(range(-1, 2), repeat=2):
if any((i, j)):
yield (x + i, y + j)
def advance(board):
newstate = set()
recalc = board | set(itertools.chain(*map(neighbors, board)))
for point in recalc:
count = sum((neigh in board)
for neigh in neighbors(point))
if count == 3 or (count == 2 and point in board):
newstate.add(point)
return newstate
을, 그래서 나는 Matplotlib animation example에서 주어진 예제를 수정하려고 :
glider = set([(0, 0), (1, 0), (2, 0), (0, 1), (1, 2)])
fig, ax = plt.subplots()
x, y = zip(*glider)
mat, = ax.plot(x, y, 'o')
def animate(i):
glider = advance(glider)
x, y = zip(*glider)
mat.set_data(x, y)
return mat,
ani = animation.FuncAnimation(fig, animate, interval=50)
plt.show()
그러나 그것은 단지 the initial points을 나타내는.
당신은 인생의 게임의 다른하기 matplotlib 구현에 관심이있을 수있는, 같은 [이 사람] (https://stackoverflow.com/questions/45653550/ 애니메이션 - 콘웨이 - 게임 라이프) 또는 [this one] (https://stackoverflow.com/questions/46196346/why-does-my-game-of-life-simulation-slow-down-to- a-crawl-within-seconds-matplot). – ImportanceOfBeingErnest