Resize shapes random

Is there a way to randomly resize shapes that are repeating?
I have a simple window full of repeating rect(). Is there a way to throw in a random option, so that each repetition is randomly shrunk or enlarged? (Thus, randomly resized)
My code:
</>
Timer timer;
void setup() {
size(450, 300);
timer = new Timer(3000);
timer.start();
smooth();
}
void draw(){
if(timer.isFinished()){
background(random(255), random(255),random(255));
timer.start();//restarts timer
fill(10,15,247, 50);//transparecny set purposely to lightly mimic background fill
for (int x = 20; x < 420; x +=100)
rect( x,50, 70, 30);
for (int x = 20; x < 420; x +=100)
rect( x, 100, 70, 30);
}
}
//timer class
class Timer {
int savedTime;
int totalTime;

Timer(int tempTotalTime) {//timer started
totalTime = tempTotalTime;//length of timer
}
void start() {
savedTime = millis();//millis makes timer run smoother than sec
}
boolean isFinished() {
int passedTime = millis() - savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}
</>

Would I have to turn the shape into a class to do this?

hi! please format your code using </> button!

1 Like