User Tools

Site Tools


cs276:mirrorhorz

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs276:mirrorhorz [2007/10/01 15:48]
scarl
cs276:mirrorhorz [2016/09/27 14:14] (current)
scarl
Line 1: Line 1:
-// Note: this code example only shows the function needed to perform the operation. +<code java> 
-// You need to provide your own setup() and draw() or other functions to test it.+  ​// 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 +  ​// Function to mirror an image around a horizontal line 
   ​   ​
-void mirrorHorizontal(PImage pi) {+  ​void mirrorHorizontal(PImage pi) {
     int mirrorPoint = pi.height / 2;     int mirrorPoint = pi.height / 2;
     color topPixel;     color topPixel;
Line 10: Line 11:
     pi.loadPixels();​     pi.loadPixels();​
     // loop through all columns     // loop through all columns
-    for (int = 0; < pi.width; ​y++) { +    for (int col = 0; col < pi.width; ​col++) { 
-       ​// loop from 0 to just before the mirrorPoint +      // loop from 0 to just before the mirrorPoint 
-       ​for (int = 0; < mirrorPoint; ​y++) { +      for (int row = 0; row < mirrorPoint; ​row++) { 
-          topPixel = pi.get(xy); +        topPixel = pi.get(colrow); 
-          // put the color into the pixel at (height-1) - y +        // put the color into the pixel at (height-1) - y 
-          pi.set(pi.height - 1 - y, y, topPixel);​ +        pi.set(col, pi.height - 1 - row, topPixel);​ 
-       ​}+        }
     }     }
     pi.updatePixels();​     pi.updatePixels();​
-}+  ​} 
 +</​code>​
cs276/mirrorhorz.1191271736.txt.gz · Last modified: 2007/10/01 15:48 by scarl