How to use the pymunk.moment_for_circle function in pymunk

To help you get started, we’ve selected a few pymunk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github viblo / pymunk / examples / flipper.py View on Github external
if event.type == QUIT:
            running = False
        elif event.type == KEYDOWN and event.key == K_ESCAPE:
            running = False
        elif event.type == KEYDOWN and event.key == K_p:
            pygame.image.save(screen, "flipper.png")
                
        elif event.type == KEYDOWN and event.key == K_j:
            r_flipper_body.apply_impulse_at_local_point(Vec2d.unit() * 40000, (-100,0))
        elif event.type == KEYDOWN and event.key == K_f:
            l_flipper_body.apply_impulse_at_local_point(Vec2d.unit() * -40000, (-100,0))
        elif event.type == KEYDOWN and event.key == K_b:
            
            mass = 1
            radius = 25
            inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
            body = pymunk.Body(mass, inertia)
            x = random.randint(115,350)
            body.position = x, 400
            shape = pymunk.Circle(body, radius, (0,0))
            shape.elasticity = 0.95
            space.add(body, shape)
            balls.append(shape)
    
    ### Clear screen
    screen.fill(THECOLORS["white"])
    
    ### Draw stuff
    space.debug_draw(draw_options)    
    
    r_flipper_body.position = 450, 100
    l_flipper_body.position = 150, 100
github CapAI / ship-sim-gym / ship_gym / game.py View on Github external
def add_goal(self, x, y):
        """Add a ball to the given space at a random position """
        self.total_goals += 1

        mass = 1
        radius = 5
        inertia = pm.moment_for_circle(mass, 0, radius, (0,0))
        body = pm.Body(mass, inertia)

        body.position = x, y
        shape = pm.Circle(body, radius, (0,0))
        shape.color = pygame.color.THECOLORS["green"]
        self.space.add(body, shape)
        shape.collision_type = 2

        goal = GameObject(body, shape)
        self.goals.append(goal)

        return goal
github pvcraven / arcade / arcade / examples / pinball.py View on Github external
def on_key_press(self, symbol: int, modifiers: int):
        if symbol == arcade.key.SPACE:
            mass = 1
            radius = BALL_RADIUS
            for x_position in range(0, 28, 1):
                moment = pymunk.moment_for_circle(mass, 0, radius)
                body = pymunk.Body(mass, moment)
                # x_position = random.randrange(2, 27)
                body.position = pymunk.Vec2d(x_position, 3)

                shape = pymunk.Circle(body, radius, pymunk.Vec2d(0, 0))
                shape.friction = 0.15
                shape.elasticity = 0.9

                self.space.add(body, shape)
                self.balls.append(body)

                body.apply_impulse_at_local_point((0, 6))
        elif symbol == arcade.key.F:
            self.right_flipper.body.apply_impulse_at_local_point((0, 100), (40, 0))
github harvitronix / rl-rc-car / rl-rc-car / sim / carmunk.py View on Github external
def create_car(self, x, y, r):
        inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0))
        self.car_body = pymunk.Body(1, inertia)
        self.car_body.position = x, y
        self.car_shape = pymunk.Circle(self.car_body, 15)
        self.car_shape.color = THECOLORS["green"]
        self.car_shape.elasticity = 1.0
        self.car_body.angle = r
        self.driving_direction = Vec2d(1, 0).rotated(self.car_body.angle)
        self.car_body.apply_impulse(self.driving_direction)
        self.space.add(self.car_body, self.car_shape)
github Caselles / NeurIPS19-SBDRL / code / reproduction_exp_CCI_VAE / flatland / flat_game / env.py View on Github external
def create_goal(self, position):
        inertia = pymunk.moment_for_circle(1, 0, self.goal_size, (0, 0))
        goal = pymunk.Body(1, inertia)
        c_shape = pymunk.Circle(goal, self.goal_size)
        c_shape.elasticity = 1.0
        if position == 'random':
            position = (
                    random.randint(self.goal_size, self.width - self.goal_size),
                    random.randint(self.goal_size, self.height - self.goal_size),
            )
        goal.position = position
        c_shape.color = THECOLORS["green"]
        c_shape.collision_type = 4
        self.space.add(goal, c_shape)
        return goal
github pvcraven / arcade / examples / pinball.py View on Github external
def on_key_press(self, symbol: int, modifiers: int):
        if symbol == arcade.key.SPACE:
            mass = 1
            radius = BALL_RADIUS
            for x_position in range(0, 28, 1):
                moment = pymunk.moment_for_circle(mass, 0, radius)
                body = pymunk.Body(mass, moment)
                # x_position = random.randrange(2, 27)
                body.position = pymunk.Vec2d(x_position, 3)

                shape = pymunk.Circle(body, radius, pymunk.Vec2d(0, 0))
                shape.friction = 0.15
                shape.elasticity = 0.9

                self.space.add(body, shape)
                self.balls.append(body)

                body.apply_impulse_at_local_point((0, 6))
        elif symbol == arcade.key.F:
            self.right_flipper.body.apply_impulse_at_local_point((0, 100), (40, 0))
github uthcode / learntosolveit / games / nanho / main.py View on Github external
def create_primate(space):
    mass = 1
    radius = 25
    inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
    body = pymunk.Body(mass, inertia)
    body.position = 10, 10
    primate = pymunk.Circle(body, radius, (0, 0))
    primate.elasticity = 0.95
    primate.friction = 25
    space.add(body, primate)
    return primate
github viblo / pymunk / examples / playground.py View on Github external
def create_ball(self, point, mass=1.0, radius=15.0):

        moment = pm.moment_for_circle(mass, 0.0, radius)
        ball_body = pm.Body(mass, moment)
        ball_body.position = Vec2d(point)
                
        ball_shape = pm.Circle(ball_body, radius)
        ball_shape.friction = 1.5
        ball_shape.collision_type = COLLTYPE_DEFAULT
        self.space.add(ball_body, ball_shape)
        return ball_shape
github samiranrl / Carrom_rl / one_step / Utils.py View on Github external
def init_striker(space, x, passthrough, action, player):

    inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0))
    body = pymunk.Body(STRIKER_MASS, inertia)
    if player == 1:
        body.position = (action[0], 145)
    if player == 2:
        body.position = (action[0], BOARD_SIZE - 136)
    body.apply_force_at_world_point((cos(action[1]) * action[2], sin(
        action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0))

    shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0))
    shape.elasticity = STRIKER_ELASTICITY
    shape.color = STRIKER_COLOR

    mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories

    sf = pymunk.ShapeFilter(mask=mask)
    shape.filter = sf
github uthcode / learntosolveit / games / nanho / slide1.py View on Github external
def add_ball(space):
    mass = 1
    radius = 14
    inertia = pymunk.moment_for_circle(mass, 0, radius)
    body = pymunk.Body(mass, inertia)
    x = random.randint(120, 380)
    body.position = x, 550
    shape = pymunk.Circle(body, radius)
    space.add(body, shape)
    return shape