Processing 3 Debugger from Processing Foundation on Vimeo.

Consider the program you wrote in to animate a blue circle. At the start of the program, it will have the value 0 and after one animation frame it will get a new value, what is that value? After another frame, it gets another new value, what is that value? Using the debugger, write down the first 40 values that are given to the variable ypos.

solution

ypos will get the values 0, 1, 2, 3, through to 38, and 39. The values keep going up, these are just the first 40 values.

Use the console to print out the value of ypos as the code from your animated blue circle is executing. What happens to the values when the blue circle is off the screen?

solution

A single new line is added at the start of the draw function that will “report” the current value in the ypos variable everytime an animation frame is drawn.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int ypos;

void setup(){
  ypos = 0;
}

void draw(){
  println(ypos);
  background(255);
  noStroke();
  fill(92, 136, 218);
  circle(width/2, ypos, 20);

  ypos++;
}

When the circle has gone off the bottom of the screen nothing changes! The variable keeps going up, but the place where it will be drawn is not visible to us anymore.