I decided to clean up the first animation that I had learned from the actionscript animation book. It can also be viewed here.

In the process I made some mistakes and learned a few things:

  1. I extended the object model to be more a mathematical graph based model - with Nodes and Edges - and I tried to abstract out the concept of forces
  2. I made the mistake of trying to iterate over the springs instead of the nodes - this makes life more complex as the forces are applied to nodes - it meant that I was accidentally applying gravity to the node once per spring attached to the node - conclusion: you most iterate over the nodes and then for each node - each force applied to that node
  3. I made the mistake of trying to apply all calculations and rewdrawing the spring lines in the same loop. This does not work because particles later on in the calculation loop will change position. Conclusion is that you need to calculate all of the nodes new positions before having a separate loop with redraws the spring lines
  4. I created the concept of MoorPoint nodes - nodes which do not move in response to forces - only the user's mouse drag and drop actions

The code can be downloaded from here.

After doing all this work - I found that the system was unstable - in terms of a small change in spring value or gravity could result in the nodes disappearing off stage. You can add damping or change the values but I decided to look at some libraries. I downloaded this as3 visualisation library - which is fantastic. They have done a great job of creating a great object orientated model that can be applied. For example they

  • have nodes and edges
  • have separated out the spring, attraction and gravitational forces into implementation of an iforce interface
  • the forces are applied to particles - ie. not to nodes - so the concepts of particle forces and a node-edge graph are kept separate
  • they have rapid node and edge iterators
  • they have the concepts of a fix() attribute that prevents the node from moving when subjected to forces - similar to a MoorPoint
  • node and edge meta data is catered for

Anyone who is working with graphs (node - edges) in no matter what language should look at the flare visualisation library