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

**URL:** <https://discourse.processing.org/t/example-5-7-bouncing-color-in-dan-shiffman-book/9309>\
**Category:** Coding Questions\
**Created:** [March 14, 2019, 8:40pm UTC](https://discourse.processing.org/t/example-5-7-bouncing-color-in-dan-shiffman-book/9309 "2019-03-14T20:40:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [March 14, 2019, 8:40pm UTC](https://discourse.processing.org/t/example-5-7-bouncing-color-in-dan-shiffman-book/9309/1 "2019-03-14T20:40:58Z")

</div>

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?

```auto
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;
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 14, 2019, 9:22pm UTC](https://discourse.processing.org/t/example-5-7-bouncing-color-in-dan-shiffman-book/9309/2 "2019-03-14T21:22:03Z")

</div>

> [@debxyz](#):
>
> if (c2 \< 0 || c2 \> 255){  
> c1Change \*= -1;  
> }

This should probably be c2Change, not c1Change.

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [March 14, 2019, 9:43pm UTC](https://discourse.processing.org/t/example-5-7-bouncing-color-in-dan-shiffman-book/9309/3 "2019-03-14T21:43:54Z")

</div>

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