# The sketch continually fills rectangles on the window:

**URL:** <https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 30, 2022, 4:58pm UTC](https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511 "2022-10-30T16:58:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![add](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@add](https://discourse.processing.org/u/add)\
**Post date:** [October 30, 2022, 4:58pm UTC](https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511/1 "2022-10-30T16:58:13Z")

</div>

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

```auto
void setup(){
  size(842,480);
    stroke(0);
  frameRate(10);
}
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));

fill(r,g,b);
rect(randomX, randomY, randomW, randomH);

}
  

```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [October 30, 2022, 5:58pm UTC](https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511/2 "2022-10-30T17:58:46Z")

</div>

Hi @add,

> [@add](#):
>
> hello everyone! how I can do this exercise?

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

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

> [@Why my draw() don't drawing continuously?](https://discourse.processing.org/t/why-my-draw-dont-drawing-continuously/39078):
>
> void setup () { size (842,480);frameRate(20);} float x = random (842); float y = random (480); float r = random (256); float g = random (256); float b = random (256); void draw () {loop ();fill (r,g,b);rect (x,y,x,y);} Can someone explain me pls why ? :3

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 30, 2022, 7:35pm UTC](https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511/3 "2022-10-30T19:35:14Z")

</div>

Hello @add,

Resources (tutorials, references and example) are here:  
[https://processing.org/](https://processing.org/)

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:

```auto
void setup()
  {
  size(300, 400);
  }

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

```

Have fun and experiment!

`:)`

---

<div class="post-metadata">

**Author:** ![add](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@add](https://discourse.processing.org/u/add)\
**Post date:** [October 31, 2022, 9:24am UTC](https://discourse.processing.org/t/the-sketch-continually-fills-rectangles-on-the-window/39511/4 "2022-10-31T09:24:28Z")

</div>

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