Hare and tortoise, aca slow and quick ball

This is the link

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

function setup() {
  createCanvas(400, 400);
  bubbles = new Bubble(100, 200, 50, 50, 1);
  bubbles1 = new Bubble(100, 300, 25, 25, 10);
}

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


class Bubble {
  constructor(x, y, size1, size2, moves){
    this.x = x;
    this.y = y;
    this.size1 = size1;
    this.size2 = size2;
    this.moves = moves;
  }
  
  move(){
    this.moves;
    //x increments by moves
    //x = x + 1
    this.x = this.x + this.moves
    //moves must be reversed
    if(this.x > width || this.x < 0){
      this.moves = this.moves * -1
      //moves = moves * (-1) etc
    }
  }
  
  show(){
    fill(0);
    stroke('red')
    ellipse(this.x, this.y, this.size1, this.size2)
  }
}

Leave a Reply