pixel trail
in
Programming Questions
•
2 years ago
Hello, im generating a glowing sphere with pixels. Before i was creating the trail effect creating a rect with alpha channel 1
fill(0, 0, 0, 1 );
rect(0, 0, width , height );
But this doesnt work with pixels[]
How can i replicate this same effect with pixels?
I need that my glowing dot can leave a trail that fade away slowly
thanks
fill(0, 0, 0, 1 );
rect(0, 0, width , height );
But this doesnt work with pixels[]
How can i replicate this same effect with pixels?
I need that my glowing dot can leave a trail that fade away slowly
thanks
- Ball [] cont;
float n=0.00f;
float q=0.03f;
int num=1;
float dens;
float nnn;
int nn;
void setup() {
size(700,700);
cont=new Ball[num];
for (int index = 0; index < num; index++) {
cont[index]=new Ball(10/((25.5f)*(index+1)),100,100,15);
}
}
void draw() {
background(250);
n=n+0.1f;
for (int index = 0; index < num; index++){
cont[index].update();
}
loadPixels();
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,(nn)*0.8f,(nn)*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;
}
}
1