Circle1D

A lame 2D "Physics" Engine

This is not really a physics engine. But it's a nice little simulation that's simple enough to fit into 170 lines (without comments/blanks) and still provide some nice simulation effects that might be useful for some use cases.

The point here is simplicity, not performance or realism. Collision detection is implemented in a very naive manner. All objects are circular. And so on... ;)

There's also a port to Javascript / HTML Canvas, and Rhody Lugo did a C++ port.

This prototype was the basis for chro.mono, a game which was open sourced in 2021 (initial closed source release 2013).

The Basics

The high-level overview of Circle1D goes like this:

The Forces

  1. There's gravity (except for FIXED or NOGRAVITY objects) pulling objects down
  2. COLLIDER objects will apply repulsion to other COLLIDER objects on overlap
  3. Joints will apply forces to their connected objects to maintain the distance

Examples

See content.py for some example setups. These examples are loaded in main.py and can be modified or disabled.

Performance

This one is interesting. On CPython 2.7.3, I get around 2.5 FPS. On PyPy 1.9.0, I get around 60 FPS once the critical code paths have been optimized by the JIT. These tests have been carried out on an Intel Core i5-2537M @ 1.40GHz using Ubuntu 12.10 (both CPython and PyPy from the repositories).

Unit Tests

There are some basic tests (use nosetests to run them) for the Vec2 class.

Thomas Perl · 2013-01-24