User Tools

Site Tools


cs276:mirrorhorz
  // 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.txt · Last modified: 2016/09/27 14:14 by scarl