How to make per box the lightest to darkest color in a Nested loop?

Hello! I’m asking for advice. I’m experimenting on how can one make the first box the lightest value then it gradually goes darker per box. So if I input the color blue, it’ll show the lightest blue at the first box of the nested loop then per box it would show a -1 to the value of the lightest box. My initial thought was I should be subtracting - 1 per loop. But I’m not sure how to implement it. How may I approach this without using HSB? Thank you so much!

int red = 255;
int blue = 255;
int green = 255;

size (492, 500);
background(255);
colorMode(RGB);


// Loop for Rectangle Generation
for (int y = 0; y < height; y = y + 50) {
  for (int x = 0; x < width; x = x + 70) {
    
    // Blue
    fill(red - 1, green - 1 , 255); 
    rect(x, y, 70, 50);
}
}

As you’ve probably noticed, all your boxes are the same color: color(254, 254, 255) - basically white.

The problem is that you are using the values (red-1) and (green-1), but not changing the values stored in those variables.

Consider this code, which does change the stored value:

int c_red = 255;
int c_blue = 255;
int c_green = 255;

size (492, 500);
background(255);
colorMode(RGB);

// Loop for Rectangle Generation
for (int y = 0; y < height; y = y + 50) {
  for (int x = 0; x < width; x = x + 70) {
    // Make there be less red and green.
    c_red = c_red - 1;
    c_green = c_green - 1
    fill(c_red, c_green, c_blue); 
    rect(x, y, 70, 50);
  }
}
2 Likes

Ahhh! I understand now. Thank you @TfGuy44 ! So I set the values in Int then it should correspond to an equation in the loop. My friend suggested on looking at increments but I found your approach easier to understand.

edit It really was incrementes!