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;
    };
}

Answers

  • I'd hope you have figured this out by now. But for the benefit of others - just put a call to background() at the top of draw:

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