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 YSorted ascending
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
    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:

    • 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.
Topic revision: r1 - 2012-11-01 - 16:16:22 - Main.troy
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF