Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testGetConstraints(self):
s = p.Space()
b1 = p.Body(1,1)
b2 = p.Body(1,1)
s.add(b1)
j1 = p.PivotJoint(b1,s.static_body,(0,0))
j2 = p.PivotJoint(b2,s.static_body,(0,0))
self.assertTrue(j1 in b1.constraints)
self.assertTrue(j1 not in b2.constraints)
self.assertTrue(j1 in s.static_body.constraints)
self.assertTrue(j2 in s.static_body.constraints)
def testPointQuery(self):
s = p.Space()
b1 = p.Body(1, 1)
b1.position = 19, 0
s1 = p.Circle(b1, 10)
s.add(s1)
b2 = p.Body(1, 1)
b2.position = 0, 0
s2 = p.Circle(b2, 10)
s.add(s2)
s1.filter = p.ShapeFilter(categories = 0b10, mask=0b01)
hits = s.point_query((23,0), 0, p.ShapeFilter(categories = 0b01, mask=0b10))
self.assertEqual(len(hits), 1)
self.assertEqual(hits[0].shape, s1)
self.assertEqual(hits[0].point, (29,0))
self.assertEqual(hits[0].distance, -6)
def testTotalKE(self):
s = p.Space()
s.gravity = 0,-100
b1 = p.Body(1, 30)
c1 = p.Circle(b1, 10)
b1.position = 5, 3
c1.collision_type = 1
c1.friction = 0.5
b2 = p.Body(body_type = p.Body.STATIC)
c2 = p.Circle(b2, 10)
c2.collision_type = 2
c2.friction = 0.8
s.add(b1, c1, b2, c2)
def post_solve(arb, space, data):
def testPointQuerySensor(self):
s = p.Space()
c = p.Circle(s.static_body, 10)
c.sensor = True
s.add(c)
hits = s.point_query((0,0), 100, p.ShapeFilter())
self.assertEqual(len(hits), 1)
def testBBQuery(self):
s = p.Space()
b1 = p.Body(1,1)
b1.position = 19,0
s1 = p.Circle(b1, 10)
s.add(s1)
b2 = p.Body(1, 1)
b2.position = 0, 0
s2 = p.Circle(b2, 10)
s.add(s2)
bb = p.BB(-7, -7, 7, 7)
hits = s.bb_query(bb, p.ShapeFilter())
self.assertEqual(len(hits), 1)
self.assertTrue(s2 in hits)
self.assertTrue(s1 not in hits)
def testIsRogue(self):
b = p.Body(1,1)
self.assert_(b.is_rogue)
s = p.Space()
s.add(b)
self.assertFalse(b.is_rogue)
def main():
### PyGame init
pygame.init()
screen = pygame.display.set_mode((width,height))
clock = pygame.time.Clock()
running = True
font = pygame.font.SysFont("Arial", 16)
### Physics stuff
space = pymunk.Space()
### Game area
# walls - the left-top-right walls
static_lines = [pymunk.Segment(space.static_body, (50, 50), (50, 550), 5)
,pymunk.Segment(space.static_body, (50, 550), (550, 550), 5)
,pymunk.Segment(space.static_body, (550, 550), (550, 50), 5)
]
for line in static_lines:
line.color = THECOLORS['lightgray']
line.elasticity = 1.0
space.add(static_lines)
# bottom - a sensor that removes anything touching it
bottom = pymunk.Segment(space.static_body, (50, 50), (550, 50), 5)
bottom.sensor = True
def __init__(self):
self.running = True
### Init pygame and create screen
pygame.init()
self.w, self.h = 600,600
self.screen = pygame.display.set_mode((self.w, self.h))
self.clock = pygame.time.Clock()
### Init pymunk and create space
self.space = pm.Space()
self.space.gravity = (0.0, -900.0)
### Walls
self.walls = []
self.create_wall_segments( [(100, 50), (500, 50)] )
## Balls
#balls = [createBall(space, (100,300))]
self.balls = []
### Polys
self.polys = []
h = 10
for y in range(1,h):
#for x in range(1, y):
x = 0
def __init__(self):
self.running = True
self.drawing = True
self.w, self.h = 600,600
self.screen = pygame.display.set_mode((self.w, self.h))
self.clock = pygame.time.Clock()
### Init pymunk and create space
self.space = pymunk.Space()
self.space.gravity = (0.0, -900.0)
self.space.sleep_time_threshold = 0.3
### ground
shape = pymunk.Segment(self.space.static_body, (5, 100), (595,100), 1.0)
shape.friction = 1.0
self.space.add(shape)
### pyramid
x=Vec2d(-270, 7.5) + (300,100)
y=Vec2d(0,0)
deltaX=Vec2d(0.5625, 1.1)*20
deltaY=Vec2d(1.125, 0.0)*20
for i in range(25):
y = Vec2d(x)
for j in range(i, 25):
def run():
# setup visualization and user input
window = pyglet.window.Window(width=600, height=600, visible=False)
keyboard = key.KeyStateHandler()
window.push_handlers(keyboard)
# help text
label = pyglet.text.Label('ESC: quit, arrow-keys: move',
font_size=20,
x=window.width//2, y=window.height//20,
anchor_x='center', anchor_y='center')
# build simulation environment
env = pymunk.Space()
# build Rob the robot
rob_mass = 1 # 1 kg
rob_radius = 0.1 * M_TO_PIXELS # 0.1 meter radius, converted to pixels for display
rob_I = pymunk.moment_for_circle(rob_mass, 0, rob_radius) # moment of inertia for disk
rob_body = pymunk.Body(rob_mass, rob_I)
rob_body.position = 300, 300
rob_shape = pymunk.Circle(rob_body, rob_radius)
rob_shape.color = 255, 0, 0 # red
# add Rob to the simulation
env.add(rob_body, rob_shape)
# define how to draw the visualization
@window.event
def on_draw():