## CS 111 - Program Design I, Spring 2013

### Lab 9

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 9

Due: Wednesday 4/3/2013 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: Lab9a.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: Lab9b.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.
• day and time of your CS 111 lab section (i.e. Monday at 3: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 9 on the Assignments Page in Blackboard.

-- Main.troy - 2013-04-01

This topic: CS111 > WebHome > CS111Spring2013 > AssignmentsS13 > Lab9S13
Topic revision: r1 - 2013-04-01 - 04:11:42 - Main.troy

 Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu WISESTHelping Women Faculty AdvanceFunded by NSF