1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| num=101 k=np.arange(1,6) t=np.linspace(0,2*np.pi,num)
Ax=[-60,0,0,0,0] Bx=[-30,8,-10,0,0]
Ay=[0,0,-12,0,14] By=[-50,-18,0,0,0]
eye=20 wigg=40
x=(np.matmul(np.array(Ax).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(Bx).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,)) y=(np.matmul(np.array(Ay).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(By).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,))
A=20 nose=np.where(x>wigg) nose_m=np.where(x>=np.max(x))
class Scope: def __init__(self,ax): self.ax=ax self.move_num=100 self.i=0
def paint(self,j): if self.i==self.move_num: self.i=0 y0=np.zeros((101,)) # import pdb;pdb.set_trace() y0[nose]=A*np.sin(2*np.pi*self.i/self.move_num)*np.exp(-np.power((nose[0]-nose_m[0]),2)/40) self.ax.cla() self.ax.plot(x,y+y0,eye,eye,'o') self.i+=1
fig,ax=plt.subplots() scope=Scope(ax) ani=animation.FuncAnimation(fig,scope.paint,interval=100) plt.show()
|