xxxxxxxxxx
89
let bubbles = [];
let fast = [];
let num = 30;
function setup() {
// createCanvas(windowWidth,windowHeight);
createCanvas(600, 400);
// createCanvas(150, 150);
for(let i=0; i<num; i++){
let x = random(width);
let y = random(height);
bubbles[i] = new Bubble(x,y);
}
for(let i=0; i<num; i++){
let x = random(width);
let y = random(height);
fast[i] = new FastBubble(x,y);
}
// frameRate(10);
}
function draw() {
background(120);
for(let i=num-1; i>=0; i--){
bubbles[i].update();
bubbles[i].display();
bubbles[i].checkEdges();
let force = p5.Vector.random2D();
force.mult(0.5);
bubbles[i].applyForce(force);
fast[i].update();
fast[i].display();
fast[i].checkEdges();
let forceFast = p5.Vector.random2D();
forceFast.mult(1.5);
fast[i].applyForce(forceFast);
for(let k=num-1; k>=0; k--){
fast[i].makeConnection(fast[k]);
}
let overlapping = false;
for(let j=num-1; j>=0; j--){
bubbles[i].makeConnection(bubbles[j]);
if (bubbles[i].intersects(fast[j])){
overlapping = true;
}
if(overlapping){
bubbles[i].changeColor(255);
bubbles[i].excite(0.1);
fast[j].changeColor(255);
fast[j].excite(0.1);
} else {
bubbles[i].changeColor(0);
bubbles[i].excite(3);
fast[j].changeColor(15);
fast[j].excite(3);
}
}
}
// for(let i=num-1; i>=0; i--){
// fast[i].update();
// fast[i].display();
// fast[i].checkEdges();
// let forceFast = p5.Vector.random2D();
// forceFast.mult(1.5);
// fast[i].applyForce(forceFast);
// let overlappingFast = false;
// for(let k=num-1; k>=0; k--){
// fast[i].makeConnection(fast[k]);
// if (i != k && fast[i].intersects(fast[k])){
// overlappingFast = true;
// }
// if(overlappingFast){
// fast[i].changeColor(255);
// fast[i].excite(1);
// } else {
// fast[i].changeColor(0);
// fast[i].excite(5);
// }
// }
// }
}