(365)
(8)
(130)
(155)
(50)
(22)
分类: python/ruby
2022-05-23 17:08:48
a,b,c = 5,3,4
def tracefunc(theta):
x = a*np.cos(theta)
y = b*np.sin(theta)
return x,y
def linefunc(x,y):
return [-c,x,c], [0,y,0]
def txtfunc(theta):
th = 180*theta/np.pi
x,y = tracefunc(theta)
lenl = np.sqrt((x c)**2 y**2)
lenr = np.sqrt((x-c)**2 y**2)
txt = f'theta={th:.2f}\nlenl={lenl:.2f},lenr={lenr:.2f}\n'
txt = f'lenl lenr={lenl lenr:.2f}'
return txt
xlim,ylim = (-a,a), (-b,b)
ts = np.linspace(0,6.28,200)
class drawani():
# func为参数方程
def __init__(self,linefunc,tracefunc,txtfunc,
ts,xlim,ylim,figsize=(16,9)):
self.linefunc 外汇跟单gendan5.com= linefunc
self.tracefunc = tracefunc
self.txtfunc = txtfunc
self.fig = plt.figure(figsize=figsize)
ax = self.fig.add_subplot(autoscale_on=false,
xlim=xlim,ylim=ylim)
ax.grid()
self.line, = ax.plot([],[],'o-',lw=2)
self.trace, = ax.plot([],[],'-',lw=1)
self.text = ax.text(0.02,0.85,'',transform=ax.transaxes)
self.xs, self.ys, self.ts = [],[],ts
self.run(ts)
def animate(self,t):
if(t==self.ts[0]):
self.xs, self.ys = [],[]
x,y = self.tracefunc(t)
self.xs.append(x)
self.ys.append(y)
self.line.set_data(self.linefunc(x,y))
self.trace.set_data(self.xs,self.ys)
self.text.set_text(self.txtfunc(t))
return self.line, self.trace, self.text
def run(self,ts):
self.ani = animation.funcanimation(self.fig, self.animate, ts, interval=5, blit=true)
plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
plt.show()
def save(self,savename):
self.ani.save(savename)