Place bodies by clicking the screen, and drag to determine their initial velocity. Change the mass of the body with the w- and s keys and change the gravitational constant with the a- and d keys. Press space to start the simulation, and press q to follow the center of mass. Zoom in and out using z and x. Press E to pan the camera around.
The program takes the position of the bodies and calculates the acceleration for the given point in space using the laws of gravity, which is done every frame. The position and velocity, however, are stored between frames. Since acceleration is the derivative of velocity, we know the change of velocity, and by knowing the velocity we know the change of position. This is a chaotic dynamical system, which means a slight change of the initial conditions is going to have a big impact on the outcome. Code by me.