A browser-based simulator built with p5.js that visualizes elastic collisions between two balls, demonstrating conservation of momentum.
- Set custom mass for the left and right balls
- Set a starting velocity for the collision
- Watch the balls collide elastically off each other and bounce off the left wall
- Live collision counter
- Clone or download this repository.
- Open
index.htmlin a web browser. - Enter values for Mass Left, Mass Right, and Start Velocity.
- Click Run to start the simulation.
- Click Stop to reset.
No build step or installation is required — the project relies on the p5.js library loaded via CDN.
Momentum-Simulator-main/
├── index.html # Page structure
└── sketch.js # Simulation logic, Circle class, and collision physics
Each ball is a Circle with a mass and velocity. When two balls collide, their new velocities are calculated using the standard 1D elastic collision formula, which conserves both momentum and kinetic energy. Collisions with the left wall simply reverse the ball's velocity.