How to animate the size of the rectangles

<
void setup() {
size(800, 620);
}

void draw() {
background(#000000);
int lw = 40;

fill(#fee445);
noStroke();

for (int i = 20; i < width; i += 60) {
for (int j = 20; j < height; j += 60) {
if (dist(25, 25, mouseX, mouseY) < 40) {
fill(#ffffff);
}
rect(i, j, lw, lw);

}

}
}
/>
I have these code for the rectangles.
Please help me to animate the rectangles, in changing size. Or may be moving from their origin.

Hi and welcome

Moving it

int x = 0;

void setup() {
  size(640, 320);
}

void draw() {
  background(0, 255, 0);


  fill(0, 0, 255);
  rect(x, 120, 50, 50);


  x = x + 1;
}

Why you are using this loop??

Idea to change size use if or whatever you want to animates it

int x = 0;

void setup() {
  size(640, 320);
}

void draw() {
  background(0, 255, 0);
  fill(0, 0, 255);
  rect(120, 120, x, x);
  x = x + 1;
}


this for loop is to create many rectangles. Actually I want to apply the effect to all the rectangles on the canvas. So please can you help with it.

I appreciate your help but I want I need the effect to all the rectangles on the canvas.

1 Like

Hi

Watch this video and search the site many useful learning you can find

https://funprogramming.org/35-A-grid-of-rotating-objects-creates-a-wave-of-rectangles.html

1 Like