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

Function update

recipes/Python/502255_Explosive_Embers/recipe-502255.py:80–104  ·  view source on GitHub ↗

Run physics and update screen.

()

Source from the content-addressed store, hash-verified

78 x, y = event.x, event.y
79
80def 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
106def wall(ball):
107 '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