pip install vpython
2.1 查看球体
from visual import *
sphere()
2.2 bounce.py简单实现
from visual import *
floor = box(length=4, height=0.5, width=4, color=color.blue)
ball = sphere(pos=(0,4,0), color=color.red)
ball.velocity = vector(0,-1,0)
dt = 0.01
while 1:
rate(100)
ball.pos = ball.pos + ball.velocity*dt
if ball.y < 1:
ball.velocity.y = -ball.velocity.y
else:
ball.velocity.y = ball.velocity.y - 9.8*dt
运行出错,看了GitHub,都没人用这个库,于是,卸了。
pip uninstall vpython
还是建议使用成熟的包,比如matplotlib,pyechart等。
参考: