Simulation of collision between moving particles with different masses inside a container, using the d3-force physics engine.
Uses two elastic collision forces, d3.forceBounce to handle elastic collisions between nodes, and d3.forceSurface for collisions with the container walls.
You can reduce the elasticity (coefficient of restitution) of the particles using the slider on the upper-left, causing kinetic energy to be lost at every collision. Elasticity of 1 indicates a pure elastic collision, while a value of 0 will cause particles to stick to each other along the collision axis.
https://cdnjs.cloudflare.com/ajax/libs/d3/4.8.0/d3.min.js
https://unpkg.com/d3-force-bounce
https://unpkg.com/d3-force-surface