xxxxxxxxxx
42
let bubbles = [];
let num = 200;
let angle = 0;
function setup() {
// createCanvas(windowWidth,windowHeight);
createCanvas(600, 400);
for(let i=0; i<num; i++){
let x = random(width);
let y = random(height);
bubbles[i] = new Bubble(x,y);
}
}
function draw() {
background(120);
bubbles[10].col = 255;
// bubbles[10].col = map(sin(angle), -1, 1, 0,255);
for(let i=num-1; i>=0; i--){
bubbles[i].update();
bubbles[i].display();
bubbles[i].borders();
let force = p5.Vector.random2D();
force.mult(0.02);
bubbles[i].applyForce(force);
let nearness = false;
for(let j=num-1; j>=0; j--){
if (i != j && bubbles[i].near(bubbles[j])){
// nearness = true;
bubbles[i].changeColor(bubbles[j]);
}
// if(nearness){
// let color = bubbles[i].checkNeighbour(bubbles[j])
// bubbles[i].changeColor(bubbles[j].col);
// }
}
}
angle += 0.001;
}