User Tools

Site Tools


cs276:mirrorhorz

This is an old revision of the document!


// Note: this code example only shows the function needed to perform the operation.
// You need to provide your own setup() and draw() or other functions to test it.

// Function to mirror an image around a horizontal line 

void mirrorHorizontal(PImage pi) {
  int mirrorPoint = pi.height / 2;
  color topPixel;

  pi.loadPixels();
  // loop through all columns
  for (int col = 0; col < pi.width; col++) {
    // loop from 0 to just before the mirrorPoint
    for (int row = 0; row < mirrorPoint; row++) {
      topPixel = pi.get(col, row);
      // put the color into the pixel at (height-1) - y
      pi.set(col, pi.height - 1 - row, topPixel);
      }
  }
  pi.updatePixels();
}
cs276/mirrorhorz.1191365129.txt.gz · Last modified: 2007/10/02 17:45 by scarl