小编Yul*_*ian的帖子

如何使用 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
Run Code Online (Sandbox Code Playgroud)

我想可视化结果,所以我尝试修改Matplotlib 动画示例中给定的示例:

glider = set([(0, 0), (1, 0), (2, 0), (0, 1), (1, 2)])

fig, …
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib conways-game-of-life

3
推荐指数
1
解决办法
8414
查看次数