CS 101 - Introduction to Computing, Spring 2007

Lab 3

This assignment will have you use JES - Jython Environment for Students.

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

Lab Assignment 3

Due: Tuesday 2/6/2007 by 11:59 pm

Write a python program in JES that will:

  1. Print out your name
  2. Print out your net-id
  3. Allow the user to select a picture from a file stored on the local machine
  4. Make a simple modification to the image (as described below)
  5. Display the modified image
  6. Save the modfied image to a file on the local machine

If you look at the python examples page for the examples from Lecture on 1/30/2007, you will see code that almost does what you need to do. Your code should be patterned after the code in the function pickAndShow (). While the function doesn't do exactly what the lab requires, you can modify the function to correctly satisfy the requirements of the lab.

The biggest thing not done in the example code is the simple modification of the image. JES comes with a number of functions that can be used for this. Some of these functions are:

Let us use addText() to modify the image. Add text is defined in the JES Help area as:
addText ()   addText(picture, xpos, ypos, text)

  picture: the picture you want to add the text to
  xpos: the x-coordinate where you want to start writing the text
  ypos: the y-coordinate where you want to start writing the text
  text: s string containing the text you want written

Takes a picture, an x position and a y position (two numbers), and some text as a string, which will get drawn into the picture.
Add some text such as Modified for CS 101 - Lab 3 or Modified by Pat Troy (of course, use your own name instead of the instructor's).

You may need to guess at the X and Y position used until you come up with something that works. Since the text is written in black, selecting a dark space on the image can be a problem. Note the the X position is in the horizontal (left to right) direction, while the Y position is in the vertical (top to bottom) direction.

The following shows and example of this.
Original Image:
Modified Image:

When saving your image, use writePictureTo(). If you hardcode the filename in your program, remember two points.

  1. If working in windows, proceed the name with an r.
  2. The directory/folder used must already exist. This is what caused Prof. Troy's problem during class on Tuesday 1/30/2007.

You are submit your program electronically by placing it in the digital drop box in blackboard. Programs that are correct and submitted by the end of the student's lab time on the Wednesday the lab assignment is discussed will receive an extra 10% on the score of the lab. When saving your program, use a meaningful name like lab3.py.

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.