Single bubbles moves along x-axis at random

This is the link.

The code:

var bubbles;

function setup() {
  createCanvas(400, 400);
  bubbles = new Bubble();
}

function draw() {
  background(220);
  bubbles.move();
  bubbles.show();
}


class Bubble {
  constructor(){
    this.x = 100;
    this.y = 200;
  }
  
  move(){
    bubbles.x = bubbles.x + random(-5, 5)
  }
  
  show(){
    fill(0);
    ellipse(bubbles.x, bubbles.y, 50, 50)
  }
}

Leave a Reply