USE TURBOWARP: https://turbowarp.org/1365302372?hqpen&fps=60 click on the balls to repel them "s" to show settings "space" to reset the simulation
This simulation uses spatial partitioning to accelerate collision detection. At the beginning of each frame, an empty uniform grid is created, with each cell sized approximately the same as a ball. This limits the number of balls that can occupy a single cell. Each ball is then inserted into the appropriate grid cell based on its position. Instead of checking for collisions with every other ball, the simulation tests for collisions only with balls in the same cell and the eight neighboring cells. As a result, the complexity of collision detection is reduced from O(n^2) to O(n).