Using molecular mechanics in Flash

In actionscript.org george.sch posted a question about the effect used in coke5 site. The leaves get pushed away when mouse goes near to them and come back when mouse moves away.

The behavior reminds a lot what I learned in school last time. Molecules attract and repel each other at the same time. The attraction and repulsion becomes stronger when the distance decreases and the forces weaken when the distance increases. However, the rate of increase and decrease for repulsion is much greater than the attraction. So, when two molecules are close to each other, both the attraction and repulsion are strong but repulsion is stronger than the attraction. As a result, the system shows that the molecules repel each other. When the two molecules are far apart from each other, both the repulsion and attraction are weak but the attraction is stronger than repulsion, so the system shows that the molecules attract each other. If the two molecules are too far way from each other, both attraction and repulsion are very weak and the system shows no interaction.

The real equation can be found at this website in the non-bonded energy part. And there’s some interesting information at this page

To implement in Flash, the calculation for attraction force is modified. It’s a simple easing equation, of the molecule has a tendency to go back to it’s original position. And here’s the example in AS3.0. The source is >>here<< (both AS2.0 and AS3.0).

  1. astgtciv

    Might be interesting to give the repelling force a different field - instead of a simple circular drop-off (which could be visualized as a half-sphere if repelling force is graphed on z vs x,y coords), it could be more of a fluctuating wave pattern - that is a circular wave field that repells at outer sides of each wave period and slightly attracts at inner sides, and changes phase and dies down in amplitude as the mouse is no longer moved.

  2. jake

    Could you post just the actionscript or provide it in the zip file?

  3. 5566

    hi guys, I’ve updated the attachment. now it’s in text format.

  4. » Blog Archive » Links: Mathematical themes with Actionscript polyGeek.com

    […] Using molecular mechanics in Flash Cool motions based on equations of attraction and repulsion. […]

  5. Lee Felarca

    Damn that’s tasty. Thanks for the explanation, too. Really useful.

  6. deceeced

    Thanks for the PM to this blog, and for the explanation of it all. Very, very cool and helpful.

Leave a Reply

For spam filtering purposes, please copy the number 3857 to the field below: