MCPcopy Create free account
hub / github.com/ActiveState/code / update

Function update

recipes/Python/502254_Bouncy_Balls/recipe-502254.py:78–101  ·  view source on GitHub ↗

Run physics and update screen.

()

Source from the content-addressed store, hash-verified

76 x, y = event.x, event.y
77
78def 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
103def wall(ball):
104 'Simulate a wall.'

Callers

nothing calls this directly

Calls 6

mutateFunction · 0.50
enumerateFunction · 0.50
crashMethod · 0.45
moveMethod · 0.45
deleteMethod · 0.45
afterMethod · 0.45

Tested by

no test coverage detected