A particle simulator with gravitational or electric interactions between particles