Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 6-8: Lines one at a time

 // No for loop here. Instead, a global variable.
int y = 0;

void setup() {
  size(200,200);
  background(255);
  // Slowing down the frame rate so we can easily see the effect.
  frameRate(5); 
}

void draw() {
  // Draw a line
  stroke(0);
  // Only one line is drawn each time through draw().
  line(0,y,width,y); 
  // Increment y
  y += 10;
  
  // Reset y back to 0 when it gets to the bottom of window
  if (y > height) {
    y = 0;
  }
}
  • http://subpixels.com subpixel

    A visible line is drawn when y==0 (the first row of pixels of the display), and an invisible, or “offscreen” line is drawn when y==height (==200).

    Not a big deal in this case, but it is helpful to keep in mind that the display pixel coordinates are from 0 to width – 1 in the x direction and 0 to height – 1 in the y direction, and is absolutely critical if using the pixels[] array method to plot points, since specifying an out of bounds index will throw a Java exception.