View Single Post
Old 08-15-2018, 09:23 AM   #32
sai'ke
Human being with feelings
 
sai'ke's Avatar
 
Join Date: Aug 2009
Location: NL
Posts: 1,453
Default

Quote:
Originally Posted by brainwreck View Post
What is this spring simulation?
Something that spreads out the blocks. It's meant for when things are initially a bit kludgy (you might see for instance that when you open a project for the first time, the blocks sort of jiggle into place).

Two forces act on the blocks:
1. A spring force, where every connection between two blocks is considered as a spring pulling them together.
2. A repellent force between all blocks which pushes blocks apart. This force decreases faster with distance than the spring force (quadratically in this case).

This system can then be simulated with a verlet algorithm which puts the blocks in non-overlapping but reasonably close positions.

It's a very simple technique and more advanced stuff exists for placing graph structures, but this seemed like a decent enough start that wouldn't cause too many hard to debug corner cases. Hitting CTRL + Enter will make it do a few iterations of the verlet algorithm if you're interested in seeing what it does.
__________________
[Tracker Plugin: Thread|Github|Reapack] | [Routing Plugin: Thread|Reapack] | [More JSFX: Thread|Descriptions|Reapack]
sai'ke is offline   Reply With Quote