Things Well Made

Craftsmanship excellence and the design of beautiful things

Thing well made: fast physics modeling of 2D cloth in javascript

March5

Andrew Hoyer’s javascript skills are awesome as you can see with this 2D cloth physics simulation with gravity written in Javascript. He uses Taylor expansion to avoid square roots in javascript (which are expensive). The code he’s written is also a thing well made — mostly very clear, concise code (except the occasional curiosity like ‘inv_m’) which by and large doesn’t need any docs.

What makes this simulation special is the speed at which everything is computed. Javascript (the language this is written in) is not exactly the most efficient language for this type of computation. This being said, much time was spent squeezing out every little detail that slows things down.

One of his inspirations is the 2D cloth simulation in a java applet using the Processing library by JRC313.com

NOTE if the simulation below is jerky, try some of the faster browsers such as Google Chrome * or Safari as their javascript support is faster than Firefox / IE currently as of March 2010.

* In the interests of full disclosure this is my own opinion but Google is my employer. But Chrome is still faster :)

Email will not be published

Website example

Your Comment:

I’ve always appreciated things that have had love, care and attention put into them. Where its obvious that the thing that was created was created for reasons above purely commercial gain.

Don McGlashan says it best in ‘Thing Well Made’ by the Mutton Birds:

To make a thing like that you’d need to know what you were about.
You’d have to know where you were going and go there in a straight line.
And everything else you’d have to shut right out.
Can you see the man who made that?
Can you see him putting it down and standing back?
Can you see the moment when he said “That’s it. That’s perfect.”?
At a time like that you wouldn’t care about your job,
Or your mortgage, or the fight you had with your wife.
‘Cause when a man holds a thing well made,
There’s connection,
There’s completeness when a man holds a thing well made.

Watch live recording of A Thing Well Made by the Mutton Birds

This site is dedicated to this song and to all those people in the world who create Things Well Made.



 

You need to log in to vote

The blog owner requires users to be logged in to be able to vote for this post.

Alternatively, if you do not have an account yet you can create one here.

Powered by Vote It Up