Gradient does not work

Hi There,

I want to make a gradient in processing with a for loop.
I can not figure out how i can solve this.

void setup() {
  color from = color(255, 165, 32);
  color to = color(72, 61, 139);
  int steps = 100;
  int w = 300 / steps;
  
  size(300, 300);
  background(51);
  noStroke();
  
  for (int i = 0; i < steps; i++) {
    fill(lerpColor(from, to, ..?... ));
    rect(i * w, 0, w, height);
  }
}

map(i, 0, steps, 0, 1) ?

Hello,

Like this?
image

This needs to be a float between 0 an 1.

i/?

Make sure ? is a floating point number so the result is a float.
Integer math (int/int) gives the result as an integer (you lose the decimal points).

10 is an integer
10.0 is a float

:)

1 Like