## CS 111 - Program Design I, Fall 2012

### Lab 10

In class we discussed an example (Lect1020b.java) that rotated an image 90 degrees clockwise. We also discussed an example (Lect1020a.java) that rotated an image around its main diagonal.

For this lab, you are to write one program that will rotate an image 180 degrees in a clockwise direction (or counter clockwise direction since both give the same result) and one program that will rotate an image 90 degrees in a counter-clockwise direction.

An example of a rotated image is shown below.
Here is the original image:

Here is the same image rotated 90 degrees clockwise:

Some key issues to think about are

• What is the size of the new rotated image based on the width and height of the original image?
• What are the X and Y coordinates of a pixel in the new rotated images based on the X and Y coordinates of the pixel in the original image?
We will need to determine the formulas for the clockwise rotation and the counter clockwise rotation.

Consider the following 5x3 "image":

 a b c d e f g h i j k l m n o
When rotated clockwise 90 degrees, it will become:
 k f a l g b m h c n i d o j e
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.
pixel Original X Original Y Rotated X Rotated Y
a
b
c
d
e
f
g
h
i
...
o
The same will need to be done with the image rotated 180 degrees. The above image would be as follows once rotated 180 degrees:
 o n m l k j i h g f e d c b a

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:

 e j o d i n c h m b g l a f k

### Lab Assignment 10

Due: Wednesday 11/7/2012 by 11:59 pm

Write two Java programs that will do the following:

1. #### Program 1: Rotate 180 Degree

1. The program is to be named: Lab10a.java
3. Allow the user to select a picture from a file stored on the local machine
4. Create an image that has been rotated 180 degrees.
5. Display the modified image
6. Save the modfied image to a file on the local machine

2. #### Program 2: Rotate 90 Counter Clockwise

1. The program is to be named: Lab10b.java
3. Allow the user to select a picture from a file stored on the local machine
4. Create an image that has been rotated 90 degrees in the counter clockwise direction.
5. Display the modified image
6. Save the modfied image to a file on the local machine

3. You must write your programs using good programming style which includes:

• Good variable names
• in-line commenting
• header block commenting for the program and each method written
Be sure to include the following with the header block comment for the program.