r/tinycode • • Apr 01 '13

Soft body physics in 998 bytes of JS

Here's what I made for js1k. It simulates a bunch of soft body blobs, collisions between them, and collisions with a moving sine terrain.

You can attract nearby blobs with mouse.

http://js1k.com/2013-spring/demo/1485

Unminified: http://jsfiddle.net/kotsoft/5TAtE/

Explanation of the math: https://skydrive.live.com/redir?resid=1F7837CC1CC2B2A4!1377&authkey=!ANyjHFa2HUjF-YQ

102 Upvotes

12 comments sorted by

3

u/seiyria Apr 01 '13

Do you happen to have an uglified version with some commentation that one could use to learn from/look at?

8

u/kotsoft Apr 01 '13

I have some unminified source here: http://jsfiddle.net/kotsoft/5TAtE/ Other features were implemented after minification.

→ More replies (2)

0

u/[deleted] Apr 01 '13

[deleted] — view deleted comment

8

u/kotsoft Apr 01 '13

Here's a document that describes the derivation of the polygon area preservation: https://skydrive.live.com/redir?resid=1F7837CC1CC2B2A4!1377&authkey=!ANyjHFa2HUjF-YQ

3

u/shizzy0 Apr 01 '13

This is a fantastic write up! Did you write it? Whoever did, I want to encourage to finish the next section!

5

u/kotsoft Apr 01 '13

Thanks! Yeah, I've been writing it while working on my entry. I hope to finish documenting everything soon.

2

u/SarahC Apr 02 '13

This is the most complex soft-body squishy particle JS program I've seen!

The closest, hard-body demo is this one: http://www.dhteumeuleu.com/aqualibrium

By a guy who writes some lovely art...

There was a green/red particle demo, but it's vanished.

I wonder - could you fiddle with the fiddle, to add mouse interaction?

I'm having trouble making it work! =(