Pymunk is a easy-to-use pythonic 2d physics library
Project description
Pymunk is a 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 other application! It is built on top of the very capable 2d physics library Chipmunk.
The first version was released in 2007 and Pymunk is still actively developed and maintained today.
Pymunk has been used with success in many projects, big and small. For example: 3 Pyweek game competition winners, more than a dozen published scientific papers and even in a self-driving car simulation! See the Showcases section on the Pymunk webpage for some examples.
2007 - 2019, Victor Blomqvist - vb@viblo.se, MIT License
This release is based on the latest Pymunk release (5.6.0), using Chipmunk 7.0.2 rev aef346fb8b (source included)
Installation
In the normal case pymunk can be installed 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
Example
Quick code example:
import pymunk # Import pymunk.. space = pymunk.Space() # Create a Space which contain the simulation space.gravity = 0,-1000 # Set its gravity body = pymunk.Body(1,1666) # Create a Body with mass and moment body.position = 50,100 # Set the position of the body poly = pymunk.Poly.create_box(body) # Create a box shape and attach to body space.add(body, poly) # Add both body and shape to the simulation while True: # Infinite loop simulation space.step(0.02) # Step the simulation one step forward
For more detailed and advanced examples, take a look at the included demos (in examples/).
Examples are not included if you install with pip install pymunk. Instead you need to download the source archive (pymunk-x.y.z.zip). Download available from https://pypi.org/project/pymunk/#files
Documentation
The source distribution of Pymunk ships with a number of demos in the examples directory, and it also contains the full documentation including API reference.
You can also find the full documentation including examples and API reference on the Pymunk homepage, http://www.pymunk.org
The Pymunk Vision
“Make 2d physics easy to include in your game”
It is (or is striving to be):
Easy to use - It should be easy to use, no complicated stuff should be needed to add physics to your game/program.
“Pythonic” - It should not be visible that a c-library (chipmunk) is in the bottom, it should feel like a Python library (no strange naming, OO, no memory handling and more)
Simple to build & install - You shouldn’t need to have a zillion of libraries installed to make it install, or do a lot of command line tricks.
Multi-platform - Should work on both Windows, *nix and OSX.
Non-intrusive - It should not put restrictions on how you structure your program and not force you to use a special game loop, it should be possible to use with other libraries like Pygame and Pyglet.
Contact & Support
- Homepage
- Stackoverflow
You can ask questions/browse old ones at Stackoverflow, just look for the Pymunk tag. http://stackoverflow.com/questions/tagged/pymunk
You can email me directly at vb@viblo.se
- Issue Tracker
Please use the issue tracker at github to report any issues you find: 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 SO or the forum other people might help as well!)
Dependencies / Requirements
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.
Python (Runs on CPython 2.7 and 3.X. Pypy and Pypy3)
Chipmunk (Compiled library already included on common platforms)
CFFI (will be installed automatically by Pip)
Setuptools (should be included with Pip)
GCC and friends (optional, you need it to compile Chipmunk)
Pygame (optional, you need it to run the Pygame based demos)
Pyglet (optional, you need it to run the Pyglet based demos)
Matplotlib & Jupyter Notebook (optional, you need it to run the Matplotlib based demos)
Sphinx (optional, you need it to build documentation)
Python 2 & Python 3
Pymunk has been tested and runs fine on both Python 2 and Python 3. It has been tested on recent versions of CPython (2 and 3) and Pypy. For an exact list of tested versions see the Travis and Appveyor test configs.
Chipmunk Compilation
This section is only required in case you dont install pymunk the normal way (pip install or setup.py install). Otherwise its handled automatically by the install command.
Pymunk is built on top of the c library Chipmunk. It uses CFFI to interface with the Chipmunk library file. Because of this Chipmunk has to be compiled before it can be used with Pymunk. Compilation has to be done with GCC or another compiler that uses the same flags.
The source distribution does not include a pre-compiled Chipmunk library file, instead you need to build it yourself.
There are basically two options, either building it automatically as part of installation using for example Pip:
> pip install pymunk-source-dist.zip
Or if you have the source unpacked / you got Pymunk by cloning its git repo, you can explicitly tell Pymunk to compile it inplace:
> python setup.py build_ext --inplace
Note that chipmunk is actually not built as a python extension, but distutils / setuptools doesn’t currently handle pure native libraries that needs to be built in a good way if built with build_clib.
The compiled file goes into the /pymunk folder (same as space.py, body.py and others).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pymunk-5.6.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7688620bdfd9b81442ee2ea12505440428b1703a2cd137c3e35d0ee5edc3ce70 |
|
MD5 | e72a3cbefa78e1ce3e34bf6958006355 |
|
BLAKE2b-256 | bb85adc32a0551d272768d4ea02b6840e287ece2186eb88a747a3868ced7d9bc |
Hashes for pymunk-5.6.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dceaa1f002e4703d5f599f27436bc13e7a92da19ee81b42a860756ed0bbfc664 |
|
MD5 | 1932012df83b0884acaeb885fc18983d |
|
BLAKE2b-256 | 5a639e48f02a1e6a642c96e824a0776059ef9fdc6c6abb7ef1053261ed2ae33c |
Hashes for pymunk-5.6.0-py2.py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30c79cf94c2d46f21737b18aabb221b36c6287298dba1498beb7123b801e556b |
|
MD5 | 04fd3eaa7e1d184bbb019f541cd55656 |
|
BLAKE2b-256 | 800f25a65edbda2d7d72c28ab150292c85293896183bf5e16cffc8e3608b8934 |
Hashes for pymunk-5.6.0-py2.py3-none-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c1bc4c58f52dfe8f206ab5eff2e652415e34adbc155c63be25d984db6331114 |
|
MD5 | f4253f95c9707c63fe97c4be2f10e7ad |
|
BLAKE2b-256 | ce50c04b94b1b426c22631129232a1bc529589d7f00fe6868e84fd2814015fc1 |
Hashes for pymunk-5.6.0-py2.py3-none-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd7fd0d3bbed006622754771a4d2d2787254de11f490dd7623a52b05d6d9b28c |
|
MD5 | ab7b8422c322b8bcc43e868696927cd6 |
|
BLAKE2b-256 | 20154d86b499370afa1255a0d152f00ed24cc453e6990818e323b7b5b3e36af1 |