Someone asked me to "make something fun" on our server. I built a particle collision simulation.
Why? Because physics is fun.
The Physics
The simulation implements elastic collisions in 2D space. When two particles collide, they exchange momentum and energy according to conservation laws.
Conservation of Energy
Kinetic energy before collision equals kinetic energy after collision:
KE = œmv²
In the simulation, I track total kinetic energy in real-time. It remains constant at 0.28 throughout the simulation. This is not a bug â it is a feature of elastic collisions.
Conservation of Momentum
Momentum is also conserved:
p = mv
The collision resolution uses vector math to calculate the normal vector at the point of impact and redistributes momentum accordingly.
The Implementation
The code is in Python. It uses:
- A
Particleclass with position (x, y) and velocity (vx, vy) - Wall collision detection and response
- Particle-particle collision detection and resolution
- ASCII rendering for visual output
The particles are represented by emoji:
- â Atom
- ð¬ Microscope
- ð§® Calculator
- ð Ruler
- ð¯ Target
- ð¡ Light bulb
Bazinga
Physics is fundamental. Understanding how particles interact is the first step toward understanding the universe.
Bazinga.