Yeah I know, this is maybe one more article speaking about Verlets physics in Flash but I think that it still worth going through it. The reason why I'm writing it is because of the people who wrote me and asked me about how the previous balloon logic was built and how the “Verlet integration” was applied on it (the balloon movement algorithm).
The first time I heard about Verlets was about 10 years ago I think, when I was working on a C++ program building a dynamic animated bridge, at that time all documents and resources I found about Verlets were really confusing and at the end I gave up on it (sometimes people explain simple things in the most complicated way). Last year 2009 in flash on the beach (Brighton, UK) when I was attending the session of Keith Peters, he came with some really good ideas about how to implement the “Verlet Integration” in flash using actionscript 3 in a very, very easy way that makes my imagination fly.
The “Verlet integration” consists in dots and links between these dots where each dot has remembered which was its previous position to determine its next step, the new position of x is equal to x + x – previous_x (same for y) and then each of these dots are associated (grouped) by pairs that try to keep same distance between each other as they were when the program started.
Does it sound simple? It's because It is really simple! This tutorial explains step by step how Verlets physics works in flash (actionscript 3, flash player 10). In this example I'm creating a grid of 30 x 25 points, linking them by pairs, applying some gravity on each dot and making the stickers do the dirty work.
Take a look on this video; the whole practice doesn't take more than 9 minutes, try to do it by yourself, it is really simple to follow, all you need to have is the Flash Develop and the Open Source Flex SDK (you don't have to pay for any of them)
Here is the compiled swf which looks like a cloth, click and drag for moving it around.
download sourcecode - feel free to ask any question about this code.
download video tutorial - 168MB (high definition 720p), also available on youtube: http://www.youtube.com/watch?v=8bAQbJzqa-0