Count up, Count down

This is a really simple bit of code that counts to 255, and back to 0 over and over again.

int count; // how many cycles have gone through
int direction; //direction of the cycle, up or down

void setup() {
  size(200,200);
}

void draw() {
  background(count);
    if (count >= 255) {
    direction = -1;
  } else if (count <= 0) {
    direction = 1;
  }
count = count + 1*direction;
println("count: " + count); 
} //end

See it work: Continue reading