For this lab, you are to write one program that will rotate an image 90 degrees in a clockwise direction and one program that will rotate an image 90 degrees in a counter-clockwise direction. To do this, you need to take the color from the pixels from the original image and store them into a diferent location in a new image.
An example of a rotated image is shown below.
Here is the original image:
Here is the same image rotated 90 degrees clockwise:
In class, we were creating a new picture that had the same height and width as our original picture. In this case the X,Y coordinate of a pixel in the original picture corresponded to the same X,Y coordinate position in the new picture. That is not the same here.
Some key issues to think about are:
We will need to determine the formulas for the clockwise rotation and the counter clockwise rotation.
Consider the following 5x3 "image":
When rotated clockwise 90 degrees, it will become:
a b c d e f g h i j k l m n o
We can (hopefully) notice a pattern between the original X and Y positions and the rotated X and Y positions by inspecting the following summary once it is filled in with the pixel position information. The table has been started to be filled in, but you should fill in the rest of it.
k f a l g b m h c n i d o j e
pixel Original X Original Y Rotated X Rotated Y a 0 0 2 0 b 1 0 2 1 c 2 0 2 2 d 3 0 2 3 e f g h i j k l m n o
You should notice in the rotated clockwise 90 degrees result that the Rotated Y values equal the Original X values while the Rotated X values correspond to the Original Y values. The exact formula for this is left up to you.
The same will need to be done with the image rotated 90 degrees in the counter-clockwise direction. The above image would be as follows once rotated:
Below is the table that need to be completed that shows the corresponding X,Y coordinate positions. It has been started to be filled in, you should complete it. Again, hopefully we will notice a pattern between the X and Y coordinates once the table had been completed. As with the clockwise rotation, the Rotated X values will correspond with the Original Y values and the Rotated Y values will correspond with the Original X values.
e j o d i n c h m b g l a f k
pixel Original X Original Y Rotated X Rotated Y a 0 0 0 4 b 1 0 0 3 c 2 0 0 2 d 3 0 0 1 e f g h i j k l m n o
Write two Java programs that will do the following:
For example for lab2, name it Lab2yournetid.java, for example if your Net ID is sfranz3, the filename would be Lab2sfranz3.javaPlease only submit source code file (the .java file, not the .class). Also, if you have any comment about your program, please write it down in the same file; please do NOT write in the "Comments" field on the submission page (this will go into a different file and will be easily missed).
NOTE: The code submitted for this lab must only access each pixel once for the rotation. You are not allowed to execute the code from rotate90clockwise three times for the rotate90CounterClockwise program or vise-versa.