The sketch continually fills rectangles on the window:

hello everyone! how I can do this exercise? The rect may never leave the bounds of the window!

void setup(){
void draw (){ 
int randomX;
int randomY;
int randomH;
int randomW;

randomX=int (random(842));
randomY= int(random(480));
randomH= int (random (480));
randomW= int (random (842));

int r= int(random (255));
int g= int (random (255));
int b= int (random (255));

rect(randomX, randomY, randomW, randomH);

1 Like

Hi @add,

Programming is about solving problems but we are not going to give you the full solution yet! :wink:

You can read this previous thread which may help you achieve what you want to do:


Hello @add,

Resources (tutorials, references and example) are here:

You must look up the reference for rect() with close attention to the syntax and parameters.

This may help you with the co-ordinate system:

void setup()
  size(300, 400);

void draw ()
  rect(mouseX, mouseY, 100, 100);
  println(mouseX, mouseY);

Have fun and experiment!


1 Like

thanks a lot @josephh , @glv ! I managed to solve the problem thanks to your help :slightly_smiling_face: