We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
dynamic blob (Read 329 times)
dynamic blob
Jun 5th, 2009, 8:46am
 
hello

i have got this code from GHOSTAGENCY.NET
if you move fast your mouse, there will be emerge little blobs from the big dynamic blob.
if you move slow your mouse, there will be just a big dynamic blob.

how can i modify the script, so there will be just a big dynamic blob, whatever you move fast the mouse.

Code:
//by Alessandro Capozzo - GHOSTAGENCY.NET
// 6 November 2003

Ball [] cont;
float n=0.00f;
float q=0.03f;
int num=5;
float dens;
float nnn;
int nn;

void setup() {
size(400,400,P3D);
frameRate(60);
cont=new Ball[num];
for (int index = 0; index < num; index++) {
cont[index]=new Ball(10/((25.5f)*(index+1)),100,100,15);
loadPixels();
}

}

void draw() {
background(250);
n=n+0.1f;
for (int index = 0; index < num; index++){
cont[index].update();
}

for (int _x = 0; _x < width; _x++) {
for (int _y = 0; _y < height; _y++) {
dens = 0;
for (int res = 0; res <num; res++) {
dens +=cont[res].dim/(sqrt(sq(_x - cont[res].bx) + sq(_y - cont[res].by)));
}
nn=(int)((dens)*(150));
nnn=50*( noise(_x*q,_y*q,n));

int c=color(nn-nnn,(nn-nnn)*0.8f,(nn-nnn)*0.5f);
pixels[_y*width+_x] =c;

}
}
updatePixels();
}

class Ball {
int bx,by;
int difX,difY;
int dim;
float xSpeed,ySpeed,ndelay;

Ball(float d,int initX,int initY,int magnitude){
ndelay=d;
bx=initX;
by=initY;
difX=0;
difY=0;
xSpeed=0.00f;
ySpeed=0.00f;
dim=magnitude;

}
void update (){
difX=mouseX-bx;
difY=mouseY-by;
xSpeed+=difX*ndelay;
ySpeed+=difY*ndelay;
xSpeed*=.9f;
ySpeed*=.9f;
bx+=xSpeed;
by+=ySpeed;

}
}
Page Index Toggle Pages: 1