Craig Russell

Web n That

I ♡… the web… php… html… css… linux… shell scripting… folding paper… dog walking… sandwiches… being outside… and most of all @vicuol ☺

JavaScript Physics Orbiting Objects

December 11th, 2011

Finally I’ve found a decent example of a JS physics simulation. This example by Jorn Zaefferer shows how to model a bouncing ball with vector arithmetic.

I’ve tweaked this code to build a simulation of objects orbiting about a point. The only key difference is that the gravity for each ball is recalculated relative to the “sun” with each animation step. I’ve also removed collision detection with the window borders.

There’s a live example here. View the source for the.. er.. source.