CS 111 - Program Design I, Spring 2014

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 prompt the user to enter if an integer value from 1 to 3. When the use enters:

  1. - rotate an image 90 degrees in a clockwise direction (as done in class in example Lect1029c.java)
  2. - rotate an image 180 degrees in a clockwise direction (or counter clockwise direction since both give the same result) or
  3. - 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:

Here is the same picture rotated 180 degrees:

caterpillarRot180.jpg

Here is the same picture rotated 90 degrees countere -clockwise:

caterpillarRot270.jpg

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/2/2013 by 11:59 pm

Write a Java program named NetIDLab9 .java that will do the following:

  1. Print out your name and your net-id
  2. Allow the user to select a picture from a file stored on the local machine
  3. Prompt the user for an integer value of 1, 2 or 3
  4. If the user enters the value of 1, call a method that will create an image that has been rotated 90 degrees clockwise
  5. If the user enters the value of 2, call a method that will create an image that has been rotated 180 degrees
  6. If the user enters the value of 3, call a method that will create an image that has been rotated 90 degrees counter-clockwise
  7. Display the rotated image
  8. Save the rotated image to a file on the local machine

  9. The code that does the rotation must be written in 3 different methods. One method for each different rotation.
  10. 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 111 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 code 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 - 2014-03-28

Edit | Attach | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2014-03-28 - 21:45:33 - 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