We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am trying to get the background to fade to 255 and than when it hits 255 it fades back to 0. Please Help.
int bw = 0;
int bw_ = 1;
void setup() {
size(300, 150);
}
void draw() {
background(bw);
bw = bw + bw_;
if (bw > 255) bw = bw - bw_;
println(bw);
}
Answers
Another way to look at this question would be: "How could I draw a triangle wave?". I like this way cause it does not need "ifs". Some thing like this would do.
triangleWave = maxNumber - abs(incrementedVar % (2*maxNumber) - maxNumber);
Cool, isn't it?
I have this old code using this, it's not drawing the wave, but using it for size and fill color. Also there is a sine wave for comparision. Check it out: