Run physics and update screen.
()
| 76 | x, y = event.x, event.y |
| 77 | |
| 78 | def update(): |
| 79 | 'Run physics and update screen.' |
| 80 | global frame |
| 81 | try: |
| 82 | for mutate in wall, floor, gravity, friction, governor: |
| 83 | for ball in balls: |
| 84 | mutate(ball) |
| 85 | for index, ball_1 in enumerate(balls[:-1]): |
| 86 | for ball_2 in balls[index+1:]: |
| 87 | ball_1.crash(ball_2) |
| 88 | for ball in balls: |
| 89 | ball.move(FPS) |
| 90 | screen.delete('animate') |
| 91 | for ball in balls: |
| 92 | x1 = ball.pos.x - ball.rad |
| 93 | y1 = ball.pos.y - ball.rad |
| 94 | x2 = ball.pos.x + ball.rad |
| 95 | y2 = ball.pos.y + ball.rad |
| 96 | screen.create_oval(x1, y1, x2, y2, fill=BALL_COLOR, tag='animate') |
| 97 | frame += 1 |
| 98 | screen.after(int((start + frame / FPS - time.clock()) * 1000), update) |
| 99 | except: |
| 100 | screen.delete(Tkinter.ALL) |
| 101 | screen.create_text(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, text=traceback.format_exc(), font='Courier 10', fill='red', tag='animate') |
| 102 | |
| 103 | def wall(ball): |
| 104 | 'Simulate a wall.' |