Pymunk is a easy-to-use pythonic 2d physics library that can be used whenever you need 2d rigid body physics from Python
.. image:: https://raw.githubusercontent.com/viblo/pymunk/master/docs/src/_static/pymunk_logo_animation.gif
Pymunk is an easy-to-use pythonic 2D physics library that can be used whenever
you need 2D rigid body physics from Python. Perfect when you need 2D physics
in your game, demo or simulation! It is built on top of the very
capable 2D physics library Chipmunk <http://chipmunk-physics.net>
_.
The first version was released in 2007 and Pymunk is still actively developed and maintained today, more than 15 years of active development!
Pymunk has been used with success in many projects, big and small. For example: 3 Pyweek game competition winners, dozens of published scientific papers and even in a self-driving car simulation! See the Showcases section on the Pymunk webpage for some examples.
2007 - 2024, Victor Blomqvist - [email protected], MIT License
This release is based on the latest Pymunk release (6.7.0), using Chipmunk 7 rev 2e8d4104b7e2380d1a73f5363a931b3eb3de8d07.
In the normal case Pymunk can be installed from PyPI with pip::
> pip install pymunk
It has one direct dependency, CFFI.
Pymunk can also be installed with conda, from the conda-forge channel::
> conda install -c conda-forge pymunk
For more detailed installation instructions, please see the complete Pymunk documentation.
Quick code example::
import pymunk # Import pymunk..
space = pymunk.Space() # Create a Space which contain the simulation
space.gravity = 0,-981 # Set its gravity
body = pymunk.Body() # Create a Body
body.position = 50,100 # Set the position of the body
poly = pymunk.Poly.create_box(body) # Create a box shape and attach to body
poly.mass = 10 # Set the mass on the shape
space.add(body, poly) # Add both body and shape to the simulation
print_options = pymunk.SpaceDebugDrawOptions() # For easy printing
for _ in range(100): # Run simulation 100 steps in total
space.step(0.02) # Step the simulation one step forward
space.debug_draw(print_options) # Print the state of the simulation
This will print (to console) the state of the simulation. For more visual,
detailed and advanced examples, take a look at the included demos.
They are included in the Pymunk install, in the pymunk.examples subpackage.
They can be run directly. To list the examples::
> python -m pymunk.examples -l
And to run one of them::
> python -m pymunk.examples.breakout
.. _contact-support:
Homepage http://www.pymunk.org/
Stackoverflow You can ask questions/browse old ones at Stackoverflow, just look for the Pymunk tag. http://stackoverflow.com/questions/tagged/pymunk
E-Mail You can email me directly at [email protected]
Issue Tracker Please use the issue tracker at Github to report any issues you find. This is also the place for feature requests: https://github.com/viblo/pymunk/issues
Regardless of the method you use I will try to answer your questions as soon as I see them. (And if you ask on Stackoverflow other people might help as well!)
The full documentation including API reference, showcase of usages and screenshots of examples is available on the Pymunk homepage, http://www.pymunk.org
"*Make 2D physics easy to include in your game*"
It is (or is striving to be):
Basically Pymunk have been made to be as easy to install and distribute as
possible, usually pip install
will take care of everything for you.
If you use any of these legacy versions of Python, please use an older Pymunk version. (It might work on newer Pymunks as well, but it's not tested, and no wheels are built.)