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":
When rotated clockwise 90 degrees, it will become:
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:
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:
Lab Assignment 10
Due: Wednesday 3/28/2011 by 11:59 pm
Write two Java programs that will do the following:
-
Program 1: Rotate 180 Degree
- The program is to be named: Lab10a.java
- Print out your name and your net-id
- Allow the user to select a picture from a file stored on
the local machine
- Create an image that has been rotated 180 degrees.
- Display the modified image
- Save the modfied image to a file on the local machine
-
Program 2: Rotate 90 Counter Clockwise
- The program is to be named: Lab10b.java
- Print out your name and your net-id
- Allow the user to select a picture from a file stored on
the local machine
- Create an image that has been rotated 90 degrees
in the counter clockwise direction.
- Display the modified image
- Save the modfied image to a file on the local machine
-
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.
- your name
- day and time of
your CS 101 lab section (i.e. Friday at 9:00)
- A description of the project.
- proper indentation of program statements
- use of blank lines to separate blocks of code.
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.