In “sketch #2: local count”, this line:

count = count = 1;

should be written as:

count = count + 1;

In addition, the code comments should not wrap around to the next line, the whole code should look like this:

// Sketch #1: Global "count"
int count = 0;

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

void draw() {
  count = count + 1;
  background(count);
}
// Sketch #2: Local "count"

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

void draw() {
  int count = 0;
  count = count + 1;
  background(count);
}
  • Kit

    Sketch 1 can’t be predicted because once count gets bigger than 255 you get wierd colours (It endlessly cycles black to blue.)

    It works if you declare count as float (I wonder where I heard that? ;-) )

  • tonyjans

    Hi i’m reading this book is awesome, but in this exercise i´m not sure what is that each code makes, why in the second part the exercise only executes one time with the local variable and why using the global variable the code is run several times

  • Anonymous

    The local variable doesn’t execute just “once.”  Draw always loops over and over again.  However, with a local variable the value is reset back to 0 each time through draw and therefore it never actually increments.