Particle p;
Particle p1;
void setup(){
//fullScreen();
size(640,320);
p = new Particle();
p1 = new Particle();
}
void draw(){
background(150);
p.display();
p1.display();
}
class Particle{
float x = random(0, width);
float y = random(0, height);
float r = random(0,30);
float xSpeed = 1;
float ySpeed = 1;
void display(){
stroke(255);
strokeWeight(5);
ellipse(x,y,r,r);
x =+ x + xSpeed;
y =+ y + ySpeed;
p.update(p1);
}
void update(Particle f1){
float d = dist(x,y,f1.x, f1.y);
if(d <= r + f1.r){
if(f1.x == x){
f1.x = -1 + f1.x;
}else if(f1.y == y){
f1.y = -1 * f1.y;
}else if(x >= width){
f1.x = -1 + f1.x;
}else if(f1.x >= width){
f1.x = -1 + f1.x;
}else if(y >= height){
f1.y = -1 * f1.y;
}else if(f1.y >= height){
f1.y = -1 * f1.y;
}
}
}
}
I was wondering how i could do the interaction of both ellipses to one another and with the environment can occur inside an object. P.S. I’m new here.