Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. Demonstrates a cool algorithm most HNers are not familiar with.

2. It's written in a language most HNers are familiar with.

3. Doesn't require any special environment to watch or play with.

4. It's open source.



I think, the algorithm is not really special btw. In fact this is very basic physics simulation. I could not decipher the JS code, but each lock can be replicated as a chain of connected nodes (i.e. there is a force between them or a constraint to keep them connected) + added radial force from the mouse + small random noise.

You keep track of each node's position, and its velocity. If connectedness is simulated as a force, it can be as simple as

1) Compute force {Fx,Fy} for each node, then integrate:

2) vx(t+dt) = vx(t) + (Fx/m) * dt

3) x(t+dt) = x(t) + vx(t+dt) * dt

If it is using constraints than the code is more complex though, but for this kind of simulation constraints are overshoot probably.

You can add gravity too, it can be a fun addition..




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: