Skip to main content

A simple Pymunk Visualization Package

Project description

Manim Pymunk

Manim Pymunk is a project that integrates the Pymunk physics engine with the Manim animation library.

Example Demo

Your browser does not support video playback.

Project Features

This project provides the following core functionalities:

Physics Simulation Integration

Seamlessly integrates the Pymunk 2D physics engine into the Manim animation framework, supporting rigid body dynamics, collision detection, and other physical phenomena.

Visualized Constraints

Provides Manim visual implementations for various physical constraints, including:

  • Positional Constraints: PinJoint, SlideJoint, PivotJoint
  • Path Constraints: GrooveJoint
  • Rotational Constraints: RotaryLimitJoint
  • Spring Constraints: DampedSpring, DampedRotarySpring
  • Transmission Constraints: GearJoint, RatchetJoint, SimpleMotor

Automatic Shape Generation

Intelligently generates Pymunk collision shapes from Manim geometric objects, supporting:

  • Basic shapes such as Circles, Lines, and Polygons.
  • Automatic subdivision sampling for complex curves.
  • Automatic convex decomposition for non-convex shapes.
  • Collision shape extraction from image pixel data.

Real-time Synchronization

Physics simulation results are automatically synchronized to Manim visual objects, supporting:

  • Real-time updates of rigid body position and rotation.
  • Visual representation of constraint forces.
  • Multi-stepping physical integration for improved stability.

Flexible Configuration

A complete interface for physical property configuration, including:

  • velocity, angular velocity, etc.
  • Shape elasticity, friction, collision types, etc.
  • Collision detection callbacks and collision filtering.

Design Principles

The design principle of this project is straightforward—it wraps a "Manim skin" over Pymunk:

  • Architecture: SpaceScene inherits from ZoomedScene. Considering camera movements, it currently encapsulates all features into a unified scene class.
  • Constraint System: Every Mobject invokes an internal updater to synchronize physical states with visuals.
  • Property Management: body, shapes, and angle are attached as Mobject attributes, initialized via mob.set(body=body).
  • Shape Generation:
    • Solid Shapes: Generates polygons directly.
    • Hollow Shapes: Constructs outlines using line segments.
    • Image Shapes: Extracts shapes using contour masks.
    • Complex Shapes: Decomposes non-convex shapes into multiple polygons.

Note: The current version provides default initialization values for all properties. You can modify them directly as needed. The core goal of this project is to facilitate the rapid creation of collision shapes.

Quick Start

Basic Workflow

from manim import *
from manim_pymunk import *


class VPivotJointExample(SpaceScene):
    def construct(self):
        # manim Mobject
        static_dot = Dot(ORIGIN)
        square = Square().move_to(static_dot)
        square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5)

        constraints = [
            VPivotJoint(static_dot, square),
            VPivotJoint(
                square,
                square2,
                pivot_world= UP*3,
            ),
        ]
        # add physics body shapes angle
        self.add_static_body(static_dot)
        self.add_dynamic_body(square, square2, angular_velocity=PI * 2)
        # add collision filter
        self.add_shapes_filter(static_dot, square, square2, group=2)
        # add constraints
        self.add_constraints(*constraints)
        # Start Physics Simulation , 
        # Note: Any animation will trigger physics simulation unless you manually remove the object from 
        # the physics controls or remove the SpaceScene updater.
        self.wait(3)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manim_pymunk-1.2.0.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manim_pymunk-1.2.0-py3-none-any.whl (58.3 kB view details)

Uploaded Python 3

File details

Details for the file manim_pymunk-1.2.0.tar.gz.

File metadata

  • Download URL: manim_pymunk-1.2.0.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for manim_pymunk-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c28af6b08053fbdf2fcfbe1b04dce8aaa0fbce198cbe2ad414464339e925c289
MD5 5d6218c321996384a1943297296fc802
BLAKE2b-256 968f01fcc037b35364888c2d039644b894297c2639a364dac868488d134881c1

See more details on using hashes here.

File details

Details for the file manim_pymunk-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: manim_pymunk-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 58.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for manim_pymunk-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c6b206ba269f4b07e2a60f218541341bff5e135f150c13611111efa1858a7ad
MD5 72b88b43611dca791fc5e225e97d1dde
BLAKE2b-256 7cbff807be54cdea983f39eae5c715c8ec5460e704ec8a8299bd0cda9209880d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page