I would like to use pybox2d
's Framework
class to visualize the simulation. However, the default screen / windows size is 640 x 480 pixels and I don't find a way to change it. I would like to know how I can change the screen size. The code below is a minimal working example:
from Box2D.examples.framework import Framework, main
from Box2D import b2EdgeShape, b2FixtureDef, b2PolygonShape, b2Vec2, b2Color
class TestObject(Framework):
def __init__(self):
super(TestObject, self).__init__()
# World
self.world.gravity = (0.0, -10.0)
self.world.CreateStaticBody(
shapes=[
b2EdgeShape(vertices=[(-10, 0), (10, 0)]),
b2EdgeShape(vertices=[(-10, 0), (-20, 20)]),
b2EdgeShape(vertices=[(10, 0), (20, 20)]),
]
)
obj_vertices = [(0.5, 0.5), (-0.5, 0.5), (-0.5, -0.5), (0.5, -0.5)]
# Create object
position = b2Vec2(12, 20)
linear_velocity = (0.0, -10.0)
self.obj = self.world.CreateDynamicBody(position=position, linearVelocity=linear_velocity, allowSleep=False)
density = 1
height, width = 6, 4
vertices = [(width * item[0], height * item[1]) for item in obj_vertices]
shape = b2PolygonShape(vertices=vertices)
fixture_def = b2FixtureDef(shape=shape, density=density)
self.obj.CreateFixture(fixture_def)
def Step(self, settings):
super(TestObject, self).Step(settings)
if __name__ == "__main__":
main(TestObject)