Back in the days of Macintosh infamy, there was a NOVA screen-saver for the Mac, called "Gravity Sucks!". It filled the screen with small to large bubbles, which attracted each other via Newton's Law of Universal Gravitation (NLUG). The strength of attraction, the mass and the velocity were all adjustable through fine controls.
Funny as it may sound, this little screen-saver was a numerical solution to the N-body Problem in two dimensions.
Attempting to model the graphics using some Maple code produces some interesting animation. The main code is similar to the code found in the document Travelling to the Moon by Solving the N-body Problem, but restricted to 2D.
The code takes care of collisions, by altering the masses of the collided masses as follows: When two masses collide, one mass takes the sum of the masses and its velocity is adjusted to compensate for the added mass using the conservation of momentum, as:
Then, one mass is zeroed-out, which is a fundamental condition which is checked for the animation to work correctly. Objects with zero mass are ignored, so the animation continues normally.