30
Mar 10Metablobs!
Following on from my last post, it occurred to me that there were a couple of problems with plain metaballs using BlendMode.ADD. Firstly circles are boring. What about having energy fields around other shapes? Secondly, although displaying metaballs using BlendMode.ADD doesn’t actually give you data about the perimeter of the blob.
In this example, I’m still using BlendMode.ADD to display the metaballs but this time I’m drawing the gradient field around a blob that is modelled by a ring of nodes connected by springs. This is similar to the way I created the Flash version of Loco Roco.
The edge of the blob is smoothed by using the node points as control handles in calls to graphics.drawCurve() and the anchor points as determined by calculating the mean between adjacent nodes. The gradient field is drawn by repeating the calls to drawCurve() and changing the line thickness to build up a gradient line.
What I ended up with is a really blobby simulation as each metaball is springing around instead of being a fixed circular shape. I also have access to a set of points which describe the edge of the blob so I could use this for collision detection or even having blobs join together into larger blobs if they get close enough.
This example also has interaction – you can grab the blobs and throw them around! Of course all this extra functionality comes at a price so the demo is quite processor intensive. The biggest bottleneck comes from having to draw each individual blob to a bitmap before applying a palette map and then drawing it again to a composite bitmap with blendMode.ADD.
Rather than building up the gradient field using the drawing API, it is also possible to use a blur or convolution filter which would have the same effect of decreasing the value of the pixels as they get further away from the edge of the source blob.
Click on the image to play with some metablobs

