Nested Loops Circles inside Circles Picture Two Nested Loops Circles inside Circles
Lab Review - Problem Extract the red plane of an image. Display the original image Display the red plane only of the image Both should be displayed simulataeously
Lab Review - Problem Analysis orig show() getRedPlane() Instantiates Picture Class Returned from redPlaneImg show()
Lab Review – The Procedure public Picture getRedPlane() { // get the pixels of this picture Pixel [] origPixData = this.getPixels(); // make a blank picture of the same size Picture newPict = new Picture(this.getWidth(), this.getHeight()); // get the pixels of the new picture Pixel [] newPixData = newPict.getPixels(); // Set the new picture's pixels to the red value in this picture // For you to supply return newPict; }
Another Problem Rotate the picture clockwise by 90 and return the rotated image as a new Picture Image?
Java Hint We can treat an image as a 2-D object using nested loops! for(int col = 0; col < this.getWidth(); col++ { for(int row = 0; row < this.getHeight(); row++) { Pixel pix = this.getPixel(col,row); // do something with pix }
Analysis 1 2 3 4 5 6 7 8 9 10 11 Rotate Clockwise (0,0) (0,1) (0,2) 1 2 3 4 5 6 7 8 9 10 11 Rotate Clockwise (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) … (2,1) (2,2) (1,2) … 4 8 1 5 9 2 6
Group Work Grab a partner and write out a method rotateClockwise() for the Picture class that will return an image rotated 90 degrees in a clockwise direction. Can we rotate the image in place?