Thanks! Well, I sort of got it working, however the Liquid Balls applet wasn't exactly what I'm looking for. The end effect I'm looking to achieve is more like this:
http://processing.org/discourse/yabb/YaBB.cgi?board=Contribution_Responsive;action=display;num=1068153198
The source code that was linked to by this guy is simple, but nearly indecipherable to me thanks to no documentation and poor variable naming.
Here is what I've managed to come up with so far. There is not as much "viscosity" as I was hoping for, and there is a problem with the equation...still trying to tweak the variables to work together. Anyway, this applet is lagging like crazy unless I turn down the strengths, but I think if the problem is pinned down, I can scale this up much higher strengths.
Main program code:
Code:import processing.opengl.*;
int ballCount;
Metaball2D[] mbs;
void setup() {
size(300,300,P3D);
background(0);
// initalize metaballs
ballCount = 3;
mbs = new Metaball2D[ballCount];
mbs[0] = new Metaball2D(100,80,1000);
mbs[1] = new Metaball2D(200,100,3000);
mbs[2] = new Metaball2D(50,100,500);
//noLoop();
frameRate(30);
}
void draw() {
background(0);
// move each ball
for(int m=0; m<ballCount; m++) { mbs[m].move(); }
// main rendering
for(int i=0; i<width; i++) {
for(int j=0; j<height; j++) {
float inf = 0.0f;
for(int m=0; m<ballCount; m++) {
inf += mbs[m].getInfluence(i,j);
}
if(inf>.2) {
stroke(inf*75,inf*60,inf*50);
point(i,j);
}
}
}
}
Metaball2D class code:
Code:class Metaball2D {
float x,y;
float strength;
float xspeed,yspeed;
float dx,dy;
Metaball2D( float _x, float _y, float _strength ) {
x = _x;
y = _y;
strength = _strength;
xspeed = random(1,2);
yspeed = random(1,2);
}
void move() {
x += xspeed;
y += yspeed;
if(x+xspeed>width || x-10<0) xspeed *= -1;
if(y+yspeed>height || y-10<0) yspeed *= -1;
}
// returns a "influence" value, given a single pixel coordinate
float getInfluence(float px, float py) {
dx = (x-px);
dy = (y-py);
return strength/(dx*dx + dy*dy+0.11f);
}
}
So whats making this applet lag? Any help appreciated