physicsplain is a simple 2D physics library written in JavaScript. The library is intended for small browser games and animations. physicsplain is lightweight in memory footprint and code size.
This library is heavily inspired by Erin Catto's GDC slides and Box2D. However, it does not provide all functionality that Box2D offers (see limitations below).
Below are a few examples as GIF animations. Check out the JavaScript examples.
Install rollup:
npm install --save-dev rollup rollup-plugin-terser
Run rollup to create file target/physicsplain-min.js
:
npx rollup -c rollup.config.js
Currently only rectangles are supported as moving bodies. Rectangles, arcs, circles, and lines are supported as fixed bodies.
Sometimes the following issues occur:
- Object collisions are not resolved properly, which results in objects moving into each other.
- Inelastic collisions and constant forces (e.g., gravity) do not go well together, which also results in object moving into each other.
Consider using Box2D or other physics libraries if your project is impacted by these limitations.
This project was inspired by the following projects and websites:
- Erin Catto's GDC slides and Box2D
- Physics simulations at myPhysicsLab
- Separating physics and graphics from Fix Your Timestep!
- Union-Find algorithm from Algorithms, 4th Edition and Wikipedia
- GIFs captured using CCapture.js