/** * Class for creating a template for a simple Java program * * @author Pat Troy: troy AT uic DOT edu */ import java.awt.Color; // Note the name of the class in the following line MUST // match the name of the file. public class Lect39a { public static void main (String[] args) { // get the first picture with the foreground image String fname = FileChooser.pickAFile(); Picture pict = new Picture (fname); Picture newlyCreatedPicture ; // call method newlyCreatedPicture = copyPicture (pict); pict.explore(); newlyCreatedPicture.show(); } // alternate way to access the pixels from three different pictures public static Picture copyPicture (Picture pict1) { // local variables int width = pict1.getWidth(); int height = pict1.getHeight(); int xPos, yPos; int rotatedX, rotatedY; Pixel p1, p2, p3; Color c1, c2, c3; // create the new picture Picture pict3 = new Picture (width, height ); for (xPos = 0 ; xPos < width ; xPos++) { for (yPos = 0 ; yPos < height ; yPos++) { // get the pixel information from the foreground original picture p1 = pict1.getPixel (xPos, yPos); c1 = p1.getColor(); // manipulate the pixels c3 = c1; rotatedX = xPos; rotatedY = yPos; // set the color in the pixel for the new picture p3 = pict3.getPixel (rotatedX, rotatedY); p3.setColor (c3); } } // end of for loop return pict3; } // end of emthod } // end of class