# Problem in code

**URL:** <https://discourse.processing.org/t/problem-in-code/33700>\
**Category:** Beginners\
**Created:** [November 23, 2021, 7:29pm UTC](https://discourse.processing.org/t/problem-in-code/33700 "2021-11-23T19:29:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dohvk](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@dohvk](https://discourse.processing.org/u/dohvk)\
**Post date:** [November 23, 2021, 7:29pm UTC](https://discourse.processing.org/t/problem-in-code/33700/1 "2021-11-23T19:29:03Z")

</div>

Hello everyone! I am a beginner in Processing and I have a problem with my code. I have random rectangles but now i want them to be aligned: 4 rows in each 4 rectangles (16 in total). Can someone help?

This is my code for the moment.

int n = 16;  
int rectSize = 100;  
int[] x = new int[n];  
int[] y = new int[n];

void setup() {  
size(700, 750);  
background(255);  
stroke(0);

for(int i=0; i \< n; i ++){  
x[i] = int(random(width));// Random horizontal position  
y[i] = int(random(height));// Random vertical position  
}  
}

void draw() {  
for (int i = 0; i \< n; i++) {  
// Si la souris est sur le carré i  
if (mouseX \>= (x[i]-rectSize)  
&& mouseX \<= (x[i]+rectSize)  
&& mouseY \>= (y[i]-rectSize)  
&& mouseY \<= (y[i]+rectSize)) {  
stroke(255, 0, 0);  
strokeWeight(3);  
fill(0);// Red  
}  
else {  
stroke(200);  
strokeWeight(3);  
fill(0); // White  
}  
rect(x[i], y[i], rectSize, 150);  
}

}

---

<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:** [November 23, 2021, 8:05pm UTC](https://discourse.processing.org/t/problem-in-code/33700/2 "2021-11-23T20:05:40Z")

</div>

Hello,

There are resources here:

> **[Welcome to Processing!](https://processing.org)**
>
> Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

This should help you generate a grid:  
[https://processing.org/reference/for.html](https://processing.org/reference/for.html)

`:)`
