Skip to main content

Pymunk is a easy-to-use pythonic 2d physics library

Project description

https://raw.githubusercontent.com/viblo/pymunk/master/docs/src/_static/pymunk_logo_animation.gif

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: 2 Pyweek game competition winners, more than 10 published scientific papers and even in a self-driving car simulation! See the Showcases section on the pymunk webpage for some examples.

2007 - 2016, Victor Blomqvist - vb@viblo.se, MIT License

This release is based on the latest Pymunk release (5.1.0), using Chipmunk 7.0 rev d7603e3927 (source included)

Installation

In the normal case pymunk can be installed with pip:

> pip install pymunk

It has one (or two) dependencies. CFFI and if not on Windows or OSX you also need a working gcc compiler.

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/).

Documentation

The source distribution of Pymunk ships with a number of demos in the examples directory, and it also contains the full documentaiton 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

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

Forum

Currently pymunk has no separate forum, but uses the general Chipmunk forum at http://chipmunk-physics.net/forum/index.php Many issues are the same, like how to create a rag doll or why a fast moving object pass through a wall. If you have a Pymunk specific question feel free to mark your post with [pymunk] to make it stand out a bit.

E-Mail

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 (Source included, and on Windows and OSX its already compiled)

  • 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

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 precompiled 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 doesnt 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


Download files

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

Source Distribution

pymunk-5.1.0.zip (6.9 MB view details)

Uploaded Source

Built Distributions

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

pymunk-5.1.0-py2.py3-none-win_amd64.whl (175.3 kB view details)

Uploaded Python 2Python 3Windows x86-64

pymunk-5.1.0-py2.py3-none-win32.whl (169.0 kB view details)

Uploaded Python 2Python 3Windows x86

File details

Details for the file pymunk-5.1.0.zip.

File metadata

  • Download URL: pymunk-5.1.0.zip
  • Upload date:
  • Size: 6.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymunk-5.1.0.zip
Algorithm Hash digest
SHA256 83b3c6db9b556af215d5cb858b88745924afab53f0025f20e89491e65f606424
MD5 a83fe3ef182bc00c6ecb39f3a17788de
BLAKE2b-256 6ec3ac05e3309dc4b4a2f450822fa0de569bf5fe40f57a56e009319f99636955

See more details on using hashes here.

File details

Details for the file pymunk-5.1.0-py2.py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for pymunk-5.1.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 293dfca1f1ee55ab79c3bdb067e7d55135599a45da87f717666d4f2f27137632
MD5 4d15462d1a55b26ef2a2bcb94c251b32
BLAKE2b-256 db5cf1b65e838117c1c5b9a119479b11821f2675862e6bcf3421022dfac62197

See more details on using hashes here.

File details

Details for the file pymunk-5.1.0-py2.py3-none-win32.whl.

File metadata

File hashes

Hashes for pymunk-5.1.0-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 9710fffcf9c9822082c9fb4b3840089b2337df3e64aa80918b8ec69e69887f92
MD5 6f4750cf5fad80c29cee22c654a8ff3a
BLAKE2b-256 789c5aadb42c2186fc1187c286b970dc5e8be1f04b09bbcbc5b78e576b5d9814

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