In this assignment you will write a method for the Picture class that mirrors a picture across a diagonal. Download this zip file and un-zip it. In the zip file there is a copy of this web page, which you can read in your browser. This assignment is due Wednesday, October 28.
Add a method called public Picture mirrorDiagonal()Notice that this method is declared to return a Picture . In the textbook, this idea is described starting in the last paragraph on page 165 up to the bottom of page 167 (in particular, Program 32).
Here is how you would use this method to mirror a picture and capture the returned image. > Picture p = new Picture("C:/cs123/mediasources/pictures/butterfly1.jpg") > Picture p2 = p.mirrorDiagonal() > p2.show()The first line creates a Picture object. The second line calls the mirrorDiagonal() method on that picture object. Since the method returns another object (which holds the mirrored image; the original object should be unchanged), we use a new reference variable p2 to refer to the new object returned by the method. The third line has this new object display itself. Here is what the new object should look like.
Here is a more detailed explanation of what the int size = Math.min(height,width);We create the new (empty) square Picture object with a line like
Picture p = new Picture(size, size);This new Picture object will (eventually) hold the mirrored image that this method should return. The method should copy the upper right triangle of the original picture into the upper right triangle of this new picture. Suppose we start with the butterfly1.jpg image.
Write a program called
Turn in a zip file called |