CS 101 - Introduction to Computing, Spring 2007

Lab 8

This lab assignment will have you write a function in jython that will created a new images that will vertically repeat a picture by an amount given as a parameter.

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

Duplicating and Image

The following code was taken from lecture on 2/22/2007. It shows how to take an image and create a new image with the original image appearing twice side-by-side.
def duplicateHorz():
  #Allow the user to pick up an image file
  file = pickAFile()
  #now convert the image in JES format
  pic = makePicture(file)

  orig_width = getWidth (pic)
  orig_height = getHeight (pic)

  new_pict = makeEmptyPicture (orig_width*2, orig_height)

  for x in range (1, orig_width):
    for y in range (1, orig_height):

      opix = getPixel(pic, x,y)

      npix1 = getPixel (new_pict, x, y)
      npix2 = getPixel (new_pict, x+orig_width, y)

      c = getColor (opix)
      setColor(npix1, c)
      setColor(npix2, c)

  openPictureTool(new_pict)

For this week's lab, you are to write a funcction that will take an integer value as its parameter. The function is to vertically diplicate an image (which is selected by the user using pickAFile()). The bew image will have the original image appear the same number of times as the value of the parameter. If the parameter has the value of 1, the function will just make a copy of the original image. If the parameter has the value of 2, the function will create an image that has 2 copies of the original image, one on top of the other. If the parameter has the value of 3, the function will create an image that has 3 copies of the original image, the first on top of the second and the second on top of the third. The value of the parameter will need to be checked to make sure it is 1 or greater.

Lab Assignment 8

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

Create a file using JES that will:

  1. Contain a comment indicating

  2. Contain a JES function that will:

If the command area of JES would be:
>>> duplicateVertical (1)
The result would be:

If the command area of JES would be:
>>> duplicateVertical (2)
The result would be:

If the command area of JES would be:
>>> duplicateVertical (3)
The result would be:

This function may call other functions that are built-in to JES or that you have written.

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.