Lab 9
In class we discussed an example
that rotated an image 90 degrees in a clockwise direction.
For this lab, you are to write
- one program that will rotate an image 90 degrees in a
counterclockwise directions and
- another program that will rotate an image 180 degrees (in either the
clockwise or countereclockwise direction).
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 counter clockwise
rotation. Consider the following 5x3 "image":
When rotated counter 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:
Lab Assignment 9
Due: Tuesday 4/29/2007 by 11:59 pm
Write two Java programs that will do the following:
-
Program 1: Rotate 90 Counter Clockwise
- The program is to be named: Lab9a
- 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
counter clockwise.
- Display the modified image
- Save the modfied image to a file on the local machine
-
Program 2: Rotate 180
- The function is to be named: Lab9b
- 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
Be sure to change comment with the name of the author to
contain the following:
- your name
- day and time of
your CS 101 lab section (i.e. Wednesday at 9:00)
- A description of the project.
- You are also to submit the Java file
electronically by
using the UNIX turnin command.
To use the UNIX turnin command to electronically hand-in your
html file using the project name of lab9. To submit the files in
lab9a.java and lab9b.java for lab9, the turnin command is entered as:
turnin -c cs101 -p lab9 lab9a.java lab9b.java
To verify what you submitted using the turnin command type:
turnin -c cs101 -p lab9 -v