Gradient along a row of squares

please format code with </> button * homework policy * asking questions


I’m trying to create a row of squares and the gradient from white to black using a for loop but I am struggling with it

I see 13 squares, so you will want a loop that runs 13 times.

Each time the loop runs, you will need to work out what color the square that this iteration draws should be. On the 0th iteration, the square should be white. On the 12th iteration, the square should be black.

Hint: What is 255 / 13?

The squares will also need to move over as they are drawn. You could simply translate() by some amount each iteration, or you could increase the X position each time by having it be a multiple of the looping variable.

Hint: What is iterating_variable * square_width?

1 Like

you could look at lerpColor in the reference