xxxxxxxxxx
48
var bubbles = []; //empty
function setup() {
createCanvas(400, 400);
}
function mousePressed(){
bubbles.push(new bubble(mouseX,mouseY));
}
function mouseDragged(){
bubbles.push(new bubble(mouseX,mouseY));
}
function draw() {
background(220);
// for(i=0;i<bubbles.length;i++){
for(i=bubbles.length -1;i>=0; i--){
// console.log(bubbles[i].delaytime)
bubbles[i].display();
bubbles[i].move();
if(bubbles[i].delaytime < 0){
bubbles.splice(i,1);
}
}
}
function bubble(xx,yy){
this.x = xx;
this.y = yy;
this.delaytime = 255;
this.display = function(){
fill(this.delaytime);
ellipse(this.x,this.y,20,20);
}
this.move = function(){
this.x = this.x + random(-1,1);
this.y = this.y + random(-1,1);
this.delaytime = this.delaytime - 1;
}
}