擅长:python、mysql、java
<p>这些只是示例程序。可以使用<a href="http://docs.python.org/dev/tutorial/classes.html" rel="nofollow">object</a>代替全局变量,如下所示:</p>
<pre><code>class GameOfLife(object):
def __init__(self, initial):
self.state = initial
def step(self):
# TODO: Game of Life implementation goes here
# Either assign a new value to self.state, or modify it
def plot_step(self):
self.step()
# TODO: Plot here
# TODO: Initialize matplotlib here
initial = [(0,0), (0,1), (0,2)]
game = GameOfLife(initial)
ani = animation.FuncAnimation(fig, game.plot_step)
plt.show()
</code></pre>
<p>如果您真的想避免类,也可以这样重写程序:</p>
^{pr2}$
<p>注意,对于非数学动画(没有标签、图形、比例等),您可能更喜欢<a href="http://pyglet.org/" rel="nofollow">pyglet</a>或{a3}。在</p>