栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【无标题】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】

做动态小球
from matplotlib import pylab
%pylab
%matplotlib notebook
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation
from matplotlib.patches import Circle, Rectangle
import matplotlib.lines as mlines
import matplotlib.image as mpimg
fig=plt.figure(figsize=(5,5))
ax=fig.add_subplot(111)
shapes=[]
cc={‘a’:{‘x’:0.1,‘y’:0.2,‘r’:0.01}}
def setup():
shapes.clear()

return shapes

def update(frame_index):
shapes.clear()
ax.clear()
if cc[‘a’][‘x’]<=0.9 and cc[‘a’][‘y’]<=0.11:
cc[‘a’][‘x’]+=0.01
if cc[‘a’][‘x’]>=0.9 and cc[‘a’][‘y’]<=0.9:
cc[‘a’][‘y’]+=0.01
if cc[‘a’][‘y’]>=0.9 and cc[‘a’][‘x’]>=0.1:
cc[‘a’][‘x’]+=-0.01
if cc[‘a’][‘x’]<=0.11 and cc[‘a’][‘y’]<=0.92:
cc[‘a’][‘y’]+=-0.01
cx=cc[‘a’]
c=Circle((cx[‘x’],cx[‘y’]),radius=cx[‘r’],facecolor=‘r’,edgecolor=‘r’)
ax.add_patch©
shapes.append©
r = Rectangle( (0.2,0.2),0.2 ,0.2, 0.3 )
ax.add_patch®
shapes.append®
e = Rectangle( (0.6,0.2),0.2 ,0.2, 0.3 )
ax.add_patch(e)
shapes.append(e)
t = Rectangle( (0.8,0.6),0.2 ,0.2, 0.3 )
ax.add_patch(t)
shapes.append(t)
x = Rectangle( (0.4,0.6),0.2 ,0.2, 0.3 )
ax.add_patch(x)
shapes.append(x)
o = Rectangle( (0,0.6),0.2 ,0.2, 0.3 )
ax.add_patch(o)
shapes.append(o)
return shapes

ani = animation.FuncAnimation(fig,update,interval=1,init_func=setup,frames=2000,blit=True)
plt.show()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1025444.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号