CS 111 - Program Design

Lab 5

Lab Assignment

Due: Wednesday 2/21/2018 by 11:59 pm

Note that this lab should be pretty simple, as we have the first exam and the first project, you deserve a bit of a break. However, this lab still count the same as the other labs toward your final letter grade

For this lab, we will manipulate a picture directly (without using turtles). We want to add some text to a picture using the existing function addText ( ) from the JES libraries.

For this lab assignment, complete the following:

  1. Prompt the user for an picture and open that picture.
  2. Once the picture has been opened, add a simple text message to the bottom left side of the picture.
  3. Then prompt the user for a filename to save the modified picture and save the picture in that file.

You should use the pickAFile() function from the JES library to prompt the user for the filename of the picture to use and again to get the filename used to save the modified image.

To add the text message, use the existing addText () function of the JES library. This method requires 4 parameters:

  1. picture - the picture to be used
  2. xpos - the pixel position of the left side of the string
  3. ypos - the pixel position of the bottom of the string
  4. text- The text message to the added to the picture
There is an optional 5th parameter that can be used to specify the color of the text. The default color of the text is black. If you look in JES under the "JES Functions" menu, you can find more detailed information about this function. It is grouped in the "Pictures" sub-menu.

We want the text to be on the bottom left side of the picture. Let us put it 20 pixels over from the left edge of the picture and 20 pixels above the bottom edge of the picture. The xpos value is simple, that will be 20. However, we must calculate the ypos value.

Fortunately, the JES library has a function getWidth() and another function getHeight(). Each of these return the distance in pixels across the width (which is the X direction) or the height (which is the Y direction) of the picture. The coordinate position of (0,0) is in the upper left corner of the picture.

Thus to calculate the value for the ypos for the addText() function, we need to subtract 20 from the height of the picture since we want the text to appear in the lower left corner of the picture. Your program must perform this calculation so the program can be used with any sized picture.

The message that you put in the picture can really be anything you want. If you can't think of anything interesting, just put "CS 111 - Lab 5" followed by your name. This sort of idea is normally used to add a caption to a picture or to add a copyright statement.

Note: you should only be adding copyright statements to pictures that you took/created yourself.

The following is an example a before and after picture:

The after picture has text in white rather than the default color of black. This was done since the original picture is mostly dark and allows the white text to be visible.

  1. Be sure to include a comment at the top of your program to contain the following:
    • your name
    • your NET-ID
    • day and time of your CS 111 lab section (i.e. Monday at 9:00)
    • A description of the project.

How assignments should be submitted

You are also to submit the python file electronically via the Assignment link in Blackboard for this lab. You are to name your file with the lab number and your netID.

Topic revision: r1 - 2018-02-15 - 18:10:15 - Main.troy
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF