MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / Playfield

Class Playfield

DemoPrograms/Demo_Graph_pymunk_2D_Graphics.py:37–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36
37class Playfield():
38 def __init__(self, graph_elem):
39 self.graph_elem = graph_elem
40 self.space = pymunk.Space()
41 self.space.gravity = 0, 200
42 self.add_wall((0, 400), (600, 400)) # ground
43 self.add_wall((0, 0), (0, 600)) # Left side
44 self.add_wall((600, 0), (600, 400)) # right side
45
46 def add_wall(self, pt_from, pt_to):
47 body = pymunk.Body(body_type=pymunk.Body.STATIC)
48 ground_shape = pymunk.Segment(body, pt_from, pt_to, 0.0)
49 ground_shape.friction = 0.8
50 ground_shape.elasticity = .99
51 self.space.add(ground_shape)
52
53 def add_balls(self):
54 self.arena_balls = []
55 for i in range(1, 200):
56 x = random.randint(0, 600)
57 y = random.randint(0, 400)
58 r = random.randint(1, 10)
59 ball = Ball(x, y, r)
60 self.arena_balls.append(ball)
61 self.space.add(ball.body, ball.shape)
62 ball.gui_circle_figure = self.graph_elem.draw_circle(
63 (x, y), r, fill_color='black', line_width=0)
64
65
66def main():

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected