Metaball experiments

Posted on February 3, 2010 in Code, Portfolio

Using derivations of the electric / gravitational field equations I worked up a very inefficient metaball application. The code places a couple of invisible objects on the stage which correspond to the locations of electric charges or gravitational bodies then sets them into motion in two dimensions. Each pixel is then analyzed each frame and colored according to the total “strength of field” at that point given all the various charges / bodies. The metaball equation, however, involves using both division and squaring, both of which are CPU intensive therefore causing this particular app to run quite slowly.

A  more advanced derivation of the equations (beyond my mathematical skills) does away with the CPU intensive operations and can speed things up to near real-time, but I never got that figured out. With no shading the application runs perfectly fine in real-time, but when shading is involved the code is just too inefficient. Oh well, it sure does look nice! The same effect can probably be achieved using some simple additive blending in OpenGL or something like that but this experiment just hasn’t gotten there. Enjoy the videos, and as always you’re welcome to download the source code following the videos.

Download the Processing sketch