Changing Size of Object Slowly

How would you go about changing the size of an object when you click the page. I realize there are many ways to do this but I specifically want the shapes to gradually increase/decrease given an array of numbers.

Tagged:

Answers

  • In what way would the array affect the size? Would the array be a series of sizes to change to?

    As you said there are many ways to do this. Below is the simplest example I can think of, a circle either grows or shrinks to some target size at a constant rate:

    int current, target;
    
    void setup() {
      size(400, 400);
    
      // Target size is half the width
      target = width/2;
    
      // Start from a random size
      current = (int)random(width);
    }
    
    void draw() {
      background(255);
      ellipse(width/2, height/2, current, current);
    
      if (current < target) current++;
      else if (current > target) current--;
    }
    
    void mousePressed() {
      // Do it again if the mouse is pressed
      current = (int)random(width);
    }
    
This discussion has been closed.