from visual import * # 改變螢幕長寬比例 scene.height = 2.5 * scene.width half = 100 floor = box(pos=(0, -half, 0), size=(2*half,1,2*half), color=color.blue) ball = sphere(pos=(0,1.5* half,0), radius=1, color=color.white,velocity=vector(0,0,0)) dt = 0.3 g = -9.8 # floor.visible = False # 增加了trail來記錄所走過的痕跡 trail = points() while 1: rate(100) trail.append(ball.pos) # trail.append(ball.pos, retain=10) ball.pos = ball.pos + ball.velocity*dt if ball.y < -half + ball.radius: break ball.velocity.y = ball.velocity.y + g*dt