CS 101 - Introduction to Computing, Spring 2007

Lab 9

This lab assignment will have you write at least two functions in jython that will create a new image that will be a 90 degree rotation in the clockwise direction of another image. This lab is to focus on the use of the return statement in JES and having a function do one and only one thing.

Reminder

The program Jython Environment for Students (or JES) is the development environment that we will use for this lab.

In the ACCC Labs that have JES, it can be found by:

  1. Clicking on Start
  2. Then click on All Programs
  3. Then click on Class Applications
  4. Then click on Engineering
  5. Finally click on Jython Environment for Students

Rotating an image

In lecture on 2/27/2007, we rotated an image in the counter-clockwise direction. This lab will have you rotate an image in the other direction. The code from that lecture is:

def rotate90counterclockwise():
  # Set up the source and target pictures
  file = pickAFile()
  pict = makePicture(file)
  wid = getWidth (pict)
  hgt = getHeight (pict)
  canvas = makeEmptyPicture(hgt, wid)
  # Now, do the actual copying--swap X & Y (correctly)!
  targetX = 1
  for sourceX in range(1,getWidth(pict)):
    targetY = 1
    for sourceY in range(1,getHeight(pict)):
      color = getColor(getPixel(pict,sourceX,sourceY))
      setColor(getPixel(canvas, targetY, wid - targetX), color)
      targetY = targetY + 1
    targetX = targetX + 1
  show(pict)
  show(canvas)
  return canvas

To do the rotation we need to figure out the corresponding positions of the pixels in the original image and the rotated image. During lecture for the counter-clockwise rotation, we determined that:

We will need to determine these formulas for the clockwise rotation. Consider the following 5x3 image:
abcde
fghij
klmno
When rotated clockwise 90 degrees, it will become:
kfa
lgb
mhc
nid
oje
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.
pixelOriginal XOriginal YRotated XRotated Y
a    
b    
c    
d    
e    
f    
g    
h    
i    
...    
o    

Lab Assignment 9

Due: Tuesday 3/20/2007 by 11:59 pm

Create a file using JES that will:

  1. Contain a comment indicating

  2. Contain a JES function that will

  3. Contain a JES function called rotate90 () that will: This function may call other functions that are built-in to JES or that you have written. Note that the code give above is close to what is needed here but it is not exact. Other than rotating in the wrong direction, the above function does more that just one thing.

Submittal of the Lab Assignment

Comments on the ACCC Labs

On the computers in the ACCC Labs there should an H: drive. This drive is actually a networked connection to your own file space maintained by the ACCC. No matter what machine you use or what lab you are in, the H: drive will access the same file space. This means that you can save a file on the H: drive on a computer in one lab and access that same file on a computer in another lab. This can be very helpful. It is suggested that you store your python program files on your H: drive.