I’m getting ready for starting a course in computational physics, and so, ignoring the fact I’m meant to be revising for an exam this Monday, I thought I’d prepare for the more exciting of the two. I’ve always wanted to code this little physics model ever since I saw it on one of those JavaScript snippet websites back when dial-up was fast and people downloaded mp3s one at a time. Those were the days.

Well, I never made it mainly because I didn’t understand how. Could this be the best thing my physics degree has taught me thus far?

What this is is a number of objects connected by elastic, then all hanging from the cursor. The elastic doesn’t like being squashed, which you can observe if you set gravity to zero and the elastic length to something big. You can instantiate multiple of trails at the same time, and tweak them live.

And it’s mighty fun to play with.

Changing the values tweaks the properties of the last-created trail.

Angle of Gravity:
Spring Constant:
Elastic Length:

You can find the commented source code at /js/elasticMouseTrailer.js. This page helped me out a little with the physics.