def update():
'Run physics and update screen.'
global frame
try:
for mutate in wall, floor, gravity, friction, governor:
for ball in balls:
mutate(ball)
for index, ball_1 in enumerate(balls[:-1]):
for ball_2 in balls[index+1:]:
ball_1.crash(ball_2)
for ball in balls:
ball.move(FPS)
screen.delete('animate')
for ball in balls:
x1 = ball.pos.x - ball.rad
y1 = ball.pos.y - ball.rad
x2 = ball.pos.x + ball.rad
y2 = ball.pos.y + ball.rad
screen.create_oval(x1, y1, x2, y2, fill=BALL_COLOR, tag='animate')
frame += 1
screen.after(int((start + frame / FPS - time.clock()) * 1000), update)
except:
screen.delete(Tkinter.ALL)
screen.create_text(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, text=traceback.format_exc(), font='Courier 10', fill='red', tag='animate')
评论列表
文章目录