For structure not generating shapes

/* 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);

250 <= 255
240 <= 255
230 <= 255

10 <= 255
0 <= 255
-10 <= 255
-20 <= 255

-300570 <= 255
-300580 <= 255

1 Like

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

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
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);
  }
}