def do_test(iters): start = time.time() world = b2.World((0, -10), True) world.create_static_body(shapes=b2.Edge((-40, 0), (40, 0))) box_half_size = (0.5, 0.5) box_density = 5.0 box_rows = 20 x = Vec2(-7, 0.75) delta_x = (0.5625, 1.25) delta_y = (1.125, 0) fixture = b2.Fixture(b2.Polygon(box=box_half_size), density=box_density) for i in range(box_rows): y = copy(x) for j in range(i, box_rows): world.create_dynamic_body(position=y, fixtures=fixture) y += delta_y x += delta_x init_time = time.time() - start range_ = range(iters) TIMESTEP = 1.0 / 60 start = time.time() for i in range_: world.step(TIMESTEP, 10, 10) world.clear_forces() step_time = time.time() - start return init_time, step_time
def do_test(iters): start = time.time() world = b2.World() columns=5 rows=16 ground = world.create_static_body( shapes=[ b2.Edge((-40,0),(40,0)), b2.Edge((20,0),(20,20)), ] ) box=b2.Fixture( shape=b2.Polygon(box=(0.5,0.5)), density=1, friction=0.3) circle=b2.Fixture( shape=b2.Circle(0.5), density=1, friction=0.3) box_start=-10 box_space=2.5 circle_start=8 circle_space=2.5 for j in range(columns): for i in range(rows): world.create_dynamic_body( fixtures=box, position=(box_start+box_space*j, 0.752 + 1.54 * i) ) world.create_dynamic_body( fixtures=circle, position=(circle_start+circle_space*j, 0.752 + 1.54 * i) ) init_time = time.time() - start range_ = range(iters) TIMESTEP = 1.0 / 60 start = time.time() for i in range_: world.step(TIMESTEP, 10, 10) world.clear_forces() step_time = time.time() - start return init_time, step_time
def __init__(self): self.world = b2.World() self.world.fixture_destruction_listener = self.fixture_destroyed self.world.joint_destruction_listener = self.joint_destroyed print('Initializing pygame framework...') # Pygame Initialization pygame.init() caption = "Pure Python Box2D Testbed - " + self.name pygame.display.set_caption(caption) # Screen and debug draw self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) self.font = pygame.font.Font(None, 15) self.groundbody = self.world.create_static_body() self.mouse_joint = None
def do_test(iters): start = time.time() world = b2.World((0, -10), True) ground = world.create_static_body(position=(0, -10)) ground.create_polygon_fixture(box=(50, 10)) body = world.create_dynamic_body(position=(0, 4)) body.create_circle_fixture(1.0, density=1.0) #body.create_polygon_fixture(box=(1, 1), density=1.0, friction=0.3) init_time = time.time() - start range_ = range(iters) start = time.time() for i in range_: world.step(0.1, 10, 10) world.clear_forces() step_time = time.time() - start return init_time, step_time
def __init__(self): self.world = b2d.World(gravity=(0, 10 * 100))
There is no graphical output for this simple example, only text. """ __version__ = "$Revision$" __date__ = "$Date$" # $Source$ import sys sys.path.extend(['..', '.']) import pypybox2d as b2 from pypybox2d.common import * # Create the world, with gravity (0, -10), and allow bodies to sleep (they use # less CPU when not moving) world = b2.World((0, -10), True) # Create a static ground body ground = world.create_static_body(position=(0, -10)) # And attach a Polygon to it. A Fixture holds the shape and contains # such information as its density, friction, etc. The box(hx, hy) # parameter indicates for the polygon to be a box of half width # 50 and half height 10. Since pypybox2d expects MKS units internally, # the box is essentially 100m wide by 10m high. For a static body, this # is just fine. ground.create_polygon_fixture(box=(50, 10)) # Create a dynamic body in the world body = world.create_dynamic_body(position=(0, 4))
if amountOfBlocks > 0: groundBodyInTheMiddle=world.CreateStaticBody( position=(xMiddleBlock, yMiddleBlock), shapes=b2PolygonShape(box=(blockWidth, blockHeight)), ) if amountOfBlocks > 1: groundBodyInTheMiddle=world.CreateStaticBody( position=(-xMiddleBlock, yMiddleBlock + blockHeight), shapes=b2PolygonShape(box=(blockWidth, blockHeight)), ) body=world.CreateDynamicBody(position=(x0,y0)) box=body.CreatePolygonFixture(box=(8,8), density=density, friction=friction) # PYPY version pypy_world = b2.World((gravity_X, gravity_Y), True) pypy_ground = pypy_world.create_static_body(position=(0, -10)) pypy_ground.create_polygon_fixture(box=(50, 10)) if amountOfBlocks > 0: pypy_middle_block = pypy_world.create_static_body(position=(xMiddleBlock, yMiddleBlock)) pypy_middle_block.create_polygon_fixture(box=(blockWidth, blockHeight)) if amountOfBlocks > 1: pypy_middle_block = pypy_world.create_static_body(position=(-xMiddleBlock, yMiddleBlock + blockHeight)) pypy_middle_block.create_polygon_fixture(box=(blockWidth, blockHeight)) pypy_box=b2.Fixture( shape=b2.Polygon(box=(8,8)), density=density, friction=friction)