phpfisx

phpfisx

A 2D physics simulation engine written in PHP.
Rigid bodies, elastic collisions, PBD constraints —
runs with just php -S and a browser.

phpfisx simulation demo

particles · gravity · collision · rigid bodies · configurable bounciness

View on GitHub Report Issue / Request Feature

Features

Rigid Bodies

Spawn boxes and circles held together by PBD distance constraints with mass-weighted correction.

Elastic Collisions

Mass-weighted impulse response for point-point and point-vs-edge collisions. Configurable restitution (0–1).

Gravity + Forces

Gravity, friction damping, and custom directional forces. Newton's second law: a = F/m.

Canvas Playback

Simulation pre-baked server-side; PNG frames streamed to an in-browser canvas player with play/pause/scrub.

Interactive Controls

Sliders for gravity, friction, bounciness, particle count, and step count. Spawn rigid bodies on demand.

Test Suite + CI

48 Pest tests covering physics, constraints, and collision. GitHub Actions matrix across PHP 8.1/8.2/8.3.

Quickstart

# Clone and install
git clone https://github.com/d4rkd0s/phpfisx
cd phpfisx
composer install

# Start dev server
php -S localhost:8000

# Open in browser
open http://localhost:8000

Requires PHP 8.1+ with ext-gd enabled and Composer. Got Yarn? yarn start does the same thing.

Roadmap

Why PHP?

There are plenty of physics engines in compiled languages (C++, Rust, Go). PHP is different: no compilation, no install friction, runs anywhere a web server exists, and it's genuinely fun to push a language into unexpected territory. phpfisx is a proof of concept that the physics are the interesting part — not the runtime.