Computer Science I

PA 02

Experimenting with Loops over Images


Due by Monday, February 16th at 9:00 AM


This assignment consists of three tasks writing four methods which should be saved in a file called PA02.py

Task 1

Create a method called simpleBorder() that takes a picture as a parameter.  This method should draw a black border several pixels inside of the image. For example,

This method should work by using pixel-based manipulation (setting the colors of pixels one at a time) rather than by using any of the method from the graphics package that we will study later.

When you have completed the simpleBorder() write a method called fancyBorder() that adds some flourish of your own choosing to this idea, say, a different color for the border, or a thicker border.

Remember -- these methods should work for any picture which is passed in as a parameter.

Task 2

Add a method named rotate180().

When sent a particular picture this method should produce and return a new Picture image that is the same image rotated 180 degrees to the right (or the left for that matter).  At first glance this might look like a vertical flip, but notice it is a very different product.

The code for this task is not particularly long, but it requires you to think carefully about which pixels are going where.

Task 3

Add a method named crop().  crop() should produce and return a new Picture image that is a subsection of the original image.  To do this, crop() takes (in addition to the original picture) four ints as parameters.  These represent the x and y coordinates of both the upper left hand corner and the lower right hand corner of a region to be cropped from the source Picture.  All pixels represented by these boundaries should be copied over.

For example, the following image was produced by the call

crop(girls,60,40,135,130);

 

Deliverables

To upload your homework for grading, log on to the homework submission system at:

Your id and password for this system are the same ones that you use to log on in the labs.

Follow the directions on the system to select the appropriate course and assignment and submit the following

In addition to this, you should print a paper copy of your code and submit this at the start of class on the due date.