Author Options:

How is fade reversed for the second cycle? Answered

At Lesson 2/Fade. I understand how the code loop works to increase brightness (from 0 up to 255) and then reverses by changing the fade amount to a minus number (line 30) until the loop count down to zero. At zero, line 30 of the code is once again made active and it still makes the fade amount a minus number. It seems to me it would need to somehow be changed to a plus number for brightness to once again be increased rather than decreased. How does the brightness amount begin to increase once again if the fade amount remains a minus number?



Best Answer 5 weeks ago

-fadeAmount serves to reverse the positive/negative of the current fadeAmount value. So if it's -5, -fadeAmount would be 5. Hope that helps clarify how the minus sign works in this context: it means "the opposite of".