function Circle(x, y, dx, dy, radius) {
  this.x = x;
  this.y = y;
  this.dx = dx;
  this.dy = dy;
  this.radius = radius;
  this.minRadius = radius;
  // this.dur = ;
  this.randomIndex = Math.floor(Math.random() * colorArray.length);
  this.color = colorArray[this.randomIndex];
  // console.log(this.dur);

  this.draw = function () {
    c.beginPath();
    c.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
    // c.strokeStyle = 'rgba(0,0,0,0)';
    // c.stroke();

    // for PASTEL COLORS
    // c.fillStyle = `rgba(${r},${g},${b},0.5)`;

    // for using colorArray of colors
    c.fillStyle = this.color;

    c.fill();
  };

  this.update = function () {
    if (this.x + this.radius > innerWidth || this.x - this.radius < 0) {
      this.dx = -this.dx;
    }
    if (this.y + this.radius > innerHeight || this.y - this.radius < 0) {
      this.dy = -this.dy;
    }

    this.x += this.dx;
    this.y += this.dy;

    // interactivity
    if (
      mouse.x - this.x < 50 &&
      mouse.x - this.x > -50 &&
      mouse.y - this.y < 50 &&
      mouse.y - this.y > -50
    ) {
      if (this.radius < maxRadius) {
        this.radius += 1;
        console.log(this.dur);
      }
    } else if (this.radius > this.minRadius) {
      this.radius -= 1;
    }

    this.draw();
  };
}
// FOR USING A colorArray of colors that is set above
FOR USING A colorArray of colors that is set above
FOR USING A colorArray of colors that is set above
function Circle(x, y, dx, dy, radius) {
  this.x = x;
  this.y = y;
  this.dx = dx;
  this.dy = dy;
  this.radius = radius;
  this.minRadius = radius;
  this.randomIndex = Math.floor(Math.random() * colorArray.length);
  this.color = colorArray[this.randomIndex];
  this.draw = function () {
    c.beginPath();
    c.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
    c.fillStyle = this.color;
    c.fill();
  };
  this.update = function () {
    if (this.x + this.radius > innerWidth || this.x - this.radius < 0) {
      this.dx = -this.dx;
    }
    if (this.y + this.radius > innerHeight || this.y - this.radius < 0) {
      this.dy = -this.dy;
    }
    this.x += this.dx;
    this.y += this.dy;
    if (
      mouse.x - this.x < 50 &&
      mouse.x - this.x > -50 &&
      mouse.y - this.y < 50 &&
      mouse.y - this.y > -50
    ) {
      if (this.radius < maxRadius) {
        this.radius += 1;
        console.log(this.dur);
      }
    } else if (this.radius > this.minRadius) {
      this.radius -= 1;
    }
    this.draw();
  };
}
function Circle ( x , y , dx , dy , radius ) { this . x = x ; this . y = y ; this . dx = dx ; this . dy = dy ; this . radius = radius ; this . minRadius = radius ; this . randomIndex = Math . floor ( Math . random ( ) * colorArray . length ) ; this . color = colorArray [ this . randomIndex ] ; this . draw = function ( ) { c . beginPath ( ) ; c . arc ( this . x , this . y , this . radius , 0 , Math . PI * 2 , false ) ; c . fillStyle = this . color ; c . fill ( ) ; } ; this . update = function ( ) { if ( this . x + this . radius > innerWidth || this . x - this . radius < 0 ) { this . dx = - this . dx ; } if ( this . y + this . radius > innerHeight || this . y - this . radius < 0 ) { this . dy = - this . dy ; } this . x += this . dx ; this . y += this . dy ; if ( mouse . x - this . x < 50 && mouse . x - this . x > - 50 && mouse . y - this . y < 50 && mouse . y - this . y > - 50 ) { if ( this . radius < maxRadius ) { this . radius += 1 ; console . log ( this . dur ) ; } } else if ( this . radius > this . minRadius ) { this . radius -= 1 ; } this . draw ( ) ; } ; }
FOR USING A colorArray of colors that is set above
FOR USING A colorArray of colors that is set above
// this.dur = ; // console.log(this.dur); // c.strokeStyle = 'rgba(0,0,0,0)'; // c.stroke(); // for PASTEL COLORS // c.fillStyle = `rgba(${r},${g},${b},0.5)`; // for using colorArray of colors // interactivity