Animation not working as expected

hi!

I'm trying to have a circle increase to a specific size and start over. it expands to the max size, then occasionally continues to grow. why is this code not working as I intend? many thanks!

var width;
var height;
var size;

function setup() {
  size = 50;

  width = window.innerWidth
  || document.documentElement.clientWidth
  || document.body.clientWidth;

  height = window.innerHeight
  || document.documentElement.clientHeight
  || document.body.clientHeight;

  createCanvas(width, height);
}

function draw(){
    ellipse(width/2, height/2, size, size);
    size = size + random(5, 20);
    if (size > 500) {
        size = 50;
    };
}
Sign In or Register to comment.