CS 100 - Computer Literacy, Fall 2004

Lab 13

This lab assignment will have you write a jython program that will display the same picture 4 times on a canvas.

Reminder

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

In the ACCC Labs, JES can be found by:

  1. Click 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

Creating a Simple Image Collage

Note: this lab is a very simple form of MP4. There is alot more to mp4 than what is discusses here.

Creating the Canvas

The first thing about creating a collage is to have a picture that can hold the collage. There are two ways to do this.
  1. Use makeEmptyPicture(width, height)

    This function will create an empty picture of the width and height specified by the two input values. To use this option you will need to figure out (or guess) at how large you will want your finished collage to be.

  2. Open an existing blank image

    We have created the image 7x95in.jpg to act as this existing blank image. It was created in Photoshop and is 7 inches wide and 9.5 inches high (according to Photoshop when it was created). This option restricts the size of the final image.

These two options allow us to create the "canvas" on which to "paint" our collage.

Transferring an Image

To transfer an image into a collage, we need to determine where the image will go on the canvas. Actually, we only need to know the position of the upper left corner of the image. Once that position is known, we can transfer all of the pixels from the original image to the canvas.

Assume we want to place the image stored in variable opict at position: column = 30, row = 55. This meant that the upper left corner of opict will be at column 30, row 55. We can use the following code. Assume the canvas is in a variable called npict.

   basex = 30
   basey = 55
 
   for x in range (1, getWidth(opict))
     for y in range (1, getHeight(opict))
       opixel = getPixel (opict, x, y)
       npixel = getPixel (npict, basex+x, basey+y)
       c = getColor (opixel)
       setColor (npixel, c)
You would repeat this operation for every image you wanted to copy to the canvas.

Lab Assignment 13

Due: Tuesday 11/30/2004 by 8:00 am

Create a file using JES that will

  1. Contain a comment indicating your Name, Net-ID, Course Name, Assignment Name and a short description of the assignment
  2. Contain a JES function that will This function may call other functions that are built-in to JES or that you have written.

If you want the images lined up horizontally, the canvas will need to have four times the width of the original image and the same height as the original image. If the original image has width of W, the first copy will be at column 1, row 1. The second image will be a column W, row 1. The third image will be a column 2*W, row 1. The fourth image will be a column 3*W, row 1. For example, look at this image:

If you want the images lined up vertically, the canvas will need to have four times the height of the original image and the same width as the original image. If the original image has height of H, the first copy will be at column 1, row 1. The second image will be a column 1, row H. The third image will be a column 1, row 2*H. The fourth image will be a column 1, row 3*h. For example, look at this image:

If you want the images lined up in a 2 by 2 grid, the canvas will need to have two times the width of the original image and the two time the height of the original image. If the original image has width of W and height of H, the first copy will be at column 1, row 1. The second image will be a column W, row 1. The third image will be a column 1, row H. The fourth image will be a column W, row 3*h. For example, look at this image:

On the ACCC lab computers, the H: drive is a permanent storage area for you. Saving files to this drive on one computer can be accessed from another computer (even another computer in a different lab). It is suggested that you save your python programs to the H: drive.

Use the UNIX turnin command to electronically hand-in your python file using the project name of lab13. Note: you will need to transfer your python file to your icarus account before you can use turnin. You can do this by using the file transfer function of SSH or by emailing your python file to your incarus account. To submit the file in <filename>.py for lab13, the turnin command is entered as:

     turnin -c troy -p lab13 <filename>.py

You are invited to post any and all images you create in the discussion board area in blackboard. You can use that area to show the class how creative you are.