The Springz library allows you to attach two objects together (in 2D space) with a spring, and simulate how they pull/push each other.
Despite the very visual nature of this application, this library doesn't know jack about graphics; it just knows how to push/pull theoretical objects around in theoretical 2D space. Making this visible to the user is up to you. (My application reads in XML data and then outputs a few frames of SVG pre-rendered animation.)
The documentation for the Springz class lists the key features at the top of it.
You can read this laboriously-written documentation, and download the file itself, from:
here (click on Springz.rb under the Files listing).
If you happen to have the Adobe SVG plugin (freely avail for Win/Mac/Linux/Solaris) installed, you can see the JS version of this library in action at -- click the green rectangle to start the simulation, and then drag objects around and/or click the orange button to scatter them about.