A high-performance, modular falling sand physics sandbox built in vanilla JavaScript and HTML5 Canvas. Experience realistic particulate physics, fluid dynamics, thermodynamics, combustion, and chemical reactions running at a silky-smooth 60+ FPS.
Replaces traditional Canvas 2D `fillRect` / `arc` draw calls with direct memory writes into a 32-bit RGBA pixel buffer on an offscreen buffer canvas, delivering a **50x–100x rendering speedup** that comfortably handles hundreds of thousands of active particles.
* **Rapid Fluid Dispersion:**
Liquids (water, acid, oil) dynamically disperse up to customizable multi-cell horizontal steps per frame, eliminating gelatinous stacking and delivering realistic splashing and surface leveling.
* **Oil & Water Emulsion & Separation:**
Water and oil mix dynamically with diagonal and horizontal swapping before buoyantly separating out according to density.
* **Lava & Rock Sinking:**
Dense molten lava plunges into water, boiling it into rising steam, and solidifies into stone that naturally sinks through liquid to the bottom of the pool.
Eliminates the legacy full-grid `updated = false` pass. Cells track `lastUpdated = currentFrame`. The simulation loop alternates horizontal scan direction (left-to-right vs. right-to-left) every frame to eliminate asymmetric pile-up bias in liquids and sand.
* **Zero-Allocation Hot Loop:**
All neighbor evaluations, directional offsets, and particle physics run with zero heap allocations or closures, preventing garbage collection pauses and stuttering.
* **Bresenham Stroke Interpolation:**
Uses Bresenham's line algorithm between consecutive cursor samples to ensure smooth, gapless lines even when drawing at high speeds.
* **Non-Destructive Canvas Resizing:**
Resizing the window or changing device orientation preserves existing particles on the canvas rather than wiping the simulation.
---
## 🧪 Element & Reaction Ecosystem
| Element | Category | Behavior & Unique Reactions |
| :--- | :--- | :--- |
| **Sand** | Solid | Granular physics; forms realistic dunes; sinks through liquids. |
| **Dirt** | Solid | Rich earthen soil; supports plant and grass roots; displaceable by explosions. |
| **Rock** | Solid | Heavy barrier; holds back blasts; naturally sinks through liquids to form riverbeds. |
| **Wood** | Solid | Rigid structural block; flammable when exposed to fire or lava. |