xxxxxxxxxx
68
class Bubble {
constructor(x,y){
this.pos = createVector(x,y);
this.vel = createVector(0,0);
this.acc = createVector(0,0);
this.d=10;
this.r = this.d/2;
this.col=0;
this.topspeed = 2;
this.glowState = false;
}
applyForce(force) {
this.acc.add(force);
}
update(){
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.mult(0);
this.vel.limit(this.topspeed);
}
display(){
noStroke();
strokeWeight(1);
fill(this.col);
ellipse(this.pos.x, this.pos.y, this.d, this.d);
}
borders() {
if (this.pos.x < -this.r) this.pos.x = width + this.r;
if (this.pos.y < -this.r) this.pos.y = height + this.r;
if (this.pos.x > width + this.r) this.pos.x = -this.r;
if (this.pos.y > height + this.r) this.pos.y = -this.r;
}
near(other){
return(dist(this.pos.x,this.pos.y,other.pos.x,other.pos.y)<=(this.d+other.d)*2);
}
checkNeighbour(other){
// if(other.col == this.col){
// return false;
// } else {return true;
// }
return(other.col);
}
changeColor(color){
if(color >= 255){
this.col = 255;
setInterval(this.defaultColor,50);
}
// if(this.glowState){
// this.col=255;
// }
// setInterval(this.defaultColor,1000);
}
defaultColor(){
this.col = 0;
// this.glowState = false;
}
}