CS 101 - Intro to Computing, Spring 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

We will need to determine the formulas for the clockwise rotation and the counter clockwise rotation.

Consider the following 5x3 "image":
abcde
fghij
klmno
When rotated clockwise 90 degrees, it will become:
kfa
lgb
mhc
nid
oje
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.
pixelOriginal XOriginal YRotated XRotated 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:
onmlk
jihgf
edcba

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:
ejo
din
chm
bgl
afk

Lab Assignment 10

Due: Wednesday 3/28/2011 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
    2. Print out your name and your net-id
    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
    2. Print out your name and your net-id
    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:

NOTE: The code submitted for this lab must only access each pixel once for the rotation. I.E. You are not allowed to execute the code from rotate90clockwise three times for the rotate90CounterClockwise program or vise-versa.

How assignments should be submitted

You are to submit your program electronically using the link for Lab 10 on the Assignments Page in Blackboard.