注册 登录
编程论坛 Python论坛

求帮忙,看一下这个程序

已被折磨死 发布于 2014-03-29 05:34, 1715 次点击
能不能帮忙看一下这个程序为什么运行错误?
主题是做一个wireworld,一种细胞自动机。

import matplotlib.pyplot as plt  
import matplotlib.animation as animation
mur = 2   
head = 1
taile =9
cond =0
def go(x,y):
    if n[x][y-1]==head and n[x][y]==cond:
        n[x][y]=head
        n[x][y-1]=taile
        n[x][y-2]=cond

def fin(x,y):
    if n[x][-1]==1:
        n[x][0]=head
        n[x][-1]=taile
        n[x][-2]=cond
def init():
    return n

def update(*args):
    for x in range(3):
        for y in range(8):
            if n[x][y-1]==head and n[x][y]==cond :
                n[x][y]=head
                n[x][y-1]=taile
                n[x][y-2]=cond
                if n[x+1][y]==3:
                    n[x][0]=head
                im.set_array(n)
                return im,
        
            fin(x,y)
                    
            
               
n=[[1,0,0,0,0,0,2,0],
   [1,0,0,0,0,0,0,0],
   [2,2,2,2,2,3,2,2]]
init()

fig = plt.figure()   
im= plt.imshow(n,interpolation = "nearest")
ani = animation.FuncAnimation(fig,update,init_func=init,frames = 300,interval=2*500,blit = False)

plt.grid(True)
plt.show()
2 回复
#2
静夜思2014-03-29 14:51
把错误提示贴上来看看
#3
xinZ2014-09-11 16:23
你的程序在我这里可以运行,不知道你的问题是什么
1