Download presentation
Presentation is loading. Please wait.
1
Nested Loops Circles inside Circles
Picture Two Nested Loops Circles inside Circles
2
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
3
Lab Review - Problem Analysis
orig setVisible() getRedPlane() Instantiates Picture Class Returned from redPlaneImg setVisible()
4
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; }
5
Another Problem Rotate the picture clockwise by 90 and return the rotated image as a new Picture Image?
6
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 }
7
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
8
Group Work Grab a partner and write out a method rotateClockwist() for the Picture class that will return an image rotated 90 degrees in a clockwise direction. Can we rotate the image in place?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.