在python中實現(xiàn)平拋運動的演示
代碼如下
# 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