# For structure not generating shapes

**URL:** <https://discourse.processing.org/t/for-structure-not-generating-shapes/27153>\
**Category:** Coding Questions\
**Created:** [January 18, 2021, 1:59am UTC](https://discourse.processing.org/t/for-structure-not-generating-shapes/27153 "2021-01-18T01:59:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Townhaus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/townhaus/32/11805_2.png) [@Townhaus](https://discourse.processing.org/u/Townhaus)\
**Post date:** [January 18, 2021, 1:59am UTC](https://discourse.processing.org/t/for-structure-not-generating-shapes/27153/1 "2021-01-18T01:59:18Z")

</div>

/\* the first for structure generates rectangles but I’m not sure why the second for structure doesn’t generate rectangles \*/

size (500, 600);  
background (115, 10, 125);  
int x = 0;  
noStroke ();

for (int i = 250; i \<= 255; i -= 10) {  
fill (255, 255, 190, i);  
rect (x, 100, 20, 175);  
x += 20;  
}

for (int i = 10; i \<= 255; i += 10) {  
fill (255, 255, 190, i);  
rect (x, 325, 20, 175);  
x += 20;  
}

fill (255, 255, 190, 10);  
rect (160, 45, 90, 10);

fill (255, 255, 190, 250);  
rect (250, 45, 90, 10);

fill (255, 255, 190, 250);  
rect (160, 545, 90, 10);

fill (255, 255, 190, 10);  
rect (250, 545, 90, 10);

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [January 18, 2021, 2:50am UTC](https://discourse.processing.org/t/for-structure-not-generating-shapes/27153/2 "2021-01-18T02:50:05Z")

</div>

> [@Townhaus](#):
>
> for (int i = 250; i \<= 255; i -= 10) {

250 \<= 255  
240 \<= 255  
230 \<= 255  
…  
10 \<= 255  
0 \<= 255  
-10 \<= 255  
-20 \<= 255  
…  
-300570 \<= 255  
-300580 \<= 255  
…

---

<div class="post-metadata">

**Author:** ![Townhaus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/townhaus/32/11805_2.png) [@Townhaus](https://discourse.processing.org/u/Townhaus)\
**Post date:** [January 24, 2021, 1:10am UTC](https://discourse.processing.org/t/for-structure-not-generating-shapes/27153/3 "2021-01-24T01:10:07Z")

</div>

How can I get the second for structure to generate rectangles with opacity increasing from left to right?

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 24, 2021, 9:32am UTC](https://discourse.processing.org/t/for-structure-not-generating-shapes/27153/4 "2021-01-24T09:32:28Z")

</div>

opacity (alpha) is the 4th parameter in a fill() function.

Just do `fill(r,g,b,i*20)` so first it will have opacity of 0, than 20, 40, 60,…

My code:

> **Code**
>
> ```auto
> size(600,600);
> background(0);
> for(int i = 0, scl = 60; i < 10; i++) {
> for(int j = 0; j < 10; j++) {
> fill(255,map(i+j*10,0,100,0,255));
> rect((i+0.25)*scl,(j+0.25)*scl,scl/2,scl/2);
> }
> }
> 
> ```
> 
> ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/549f23419d42db224c1f8e081faf2a29c8304fef.png)
