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