Millions of bubbles moving randomly

Link is here

//var bubbles;
//var bubbles1;
let bubbles = [];

function setup() {
  createCanvas(windowWidth, windowHeight);
  for(var i = 0; i < 1000; i++){
    let x = random(width);
    let y = random(height);
    bubbles[i] = new Bubble(x, y, 50, 50);
  }
  
}

function draw() {
  background(255);
  for(var i = 0; i < bubbles.length; i++){
    bubbles[i].move();
    bubbles[i].show();
  }
}


class Bubble {
  constructor(x, y, size1, size2){
    this.x = x;
    this.y = y;
    this.size1 = size1;
    this.size2 = size2;
  }
  
  move(){
    
    this.x = this.x + random(-5, 5)
    this.y = this.y + random(-5, 5)
  }
  
  show(){
    fill(0, 10);
    stroke('black')
    //noStroke()
    ellipse(this.x, this.y, this.size1, this.size2)
  }
}

Leave a Reply