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

Function initialise

recipes/Python/502253_Space_Balls/recipe-502253.py:22–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 mainloop()
21
22def initialise():
23 global balls, x, y, screen, lock
24 space = WALL_SPACE + BALL_RADIUS
25 balls = []
26 for ball in xrange(BALLS):
27 table = randint(0, 3)
28 if table >> 1:
29 x = randint(space, SCREEN_WIDTH - space)
30 y = -START_SPACE if table & 1 else START_SPACE + SCREEN_HEIGHT
31 else:
32 x = -START_SPACE if table & 1 else START_SPACE + SCREEN_WIDTH
33 y = randint(space, SCREEN_HEIGHT - space)
34 balls.append(Ball(x, y, BALL_RADIUS))
35 root = Tk()
36 root.resizable(False, False)
37 root.title('Space Balls')
38 x = (root.winfo_screenwidth() - SCREEN_WIDTH) / 2
39 y = (root.winfo_screenheight() - SCREEN_HEIGHT) / 2
40 root.geometry('%dx%d+%d+%d' % (SCREEN_WIDTH, SCREEN_HEIGHT, x, y))
41 root.bind_all('<Escape>', lambda event: event.widget.quit())
42 root.bind('<Configure>', move)
43 screen = Canvas(root, width=SCREEN_WIDTH, height=SCREEN_HEIGHT, background=BACKGROUND)
44 screen.after(1000 / FPS, update)
45 screen.after(10000 / FPS, unlock)
46 screen.pack()
47 lock = True
48
49def move(event):
50 global x, y

Callers 1

mainFunction · 0.70

Calls 9

xrangeClass · 0.85
BallClass · 0.50
TkClass · 0.50
appendMethod · 0.45
titleMethod · 0.45
quitMethod · 0.45
bindMethod · 0.45
afterMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected