Example 5-7 ~ BOUNCING COLOR ~ in Dan Shiffman book

When I run the code below (from Shiffman, p87, example 5-7, the color gradates back and forth only once. Why doesn’t it endlessly bounce back and forth?
I thought if the “if” statement included an " = * -1" this would continually reverse the color gradation.
Please, what am I missing here?

float c1 = 0;
float c2 = 255;

float c1Change = 1;
float c2Change = -1;

void setup(){
  size(400,400);
}
void draw(){
  noStroke();
  
  fill(c1, 0, c2);
  rect(0, 0, width/2, height);
  
  fill(c2, 0, c1);
  rect(width/2, 0, width/2, height);
  
  c1 = c1 + c1Change;
  c2 = c2 + c2Change;
  
  if (c1 < 0 || c2 > 255){
    c1Change *= -1;
  }
  if (c2 < 0 || c2 > 255){
    c1Change *= -1;
  }
}
1 Like

This should probably be c2Change, not c1Change.

2 Likes

Oh yes!! I made the correction and it now works.
Thank you!

1 Like