在python中实现平抛运动的演示
代码如下
# coding: utf-8
from Tkinter import *
from time import sleep
root = Tk()
cv = Canvas(root, width=600, height=600)
cv.pack()
ball = cv.create_oval(0,10,20,30,fill='red')
x = 10
y = 20
v_y = 0
v_x = 15
t = 0.1
while True:
v_y = v_y + 9.8 * t
new_y = y + v_y * t
new_x = x + v_x * t
del_x = v_x * t
del_y = v_y * t
cv.move(ball,del_x,del_y)
cv.update()
y = new_y
x = new_x
if x >=590 or x <= 10:
v_x = - v_x
if y >= 590:
v_y = - v_y
简书代码不会输入,
链接在这: https://pan.baidu.com/s/1hrY5BEG
密码: v689