If you need something much more true to the laws of physics, you can look at this demo:
The DEMO FILE is zipped with the required Javascript files (all reside in the same folder).
I have included a number of resource URLs in the JS code, that will be helpful in figuring out how this works.