CS-171

Program Assignment 2

 

Objective

The objectives of this assignment include the following:

 

Assignment

The basic output of this assignment is to posterize a picture, which reduces the number of colors in a picture.  We will accomplish this by adding a method to the provided Picture class, defined in Picture.java.  This class definition exists in the bookClasses folder that you copied to your U drive.  You can edit the Picture.java file in-place (i.e. without having to copy the folder elsewhere first).  As we progress through the book, we will make additional changes to this and to other of the provided classes.

Assignment Specification:

For basic completion of the assignment, which will earn 75 out of 100 points, complete the following:

Write a method named posterize that posterizes the current Picture object.  To do this you must first extract all of the pixels in the Picture into an array.  This is done the same way we have done it in class.  Next, you will use a for-loop to iterate through all of the pixels and change the color of the pixel according to the following rules:

Finally, the posterize method should redisplay the image so that the changes appear.  (Hint: see the book for how to redisplay an image.  It is not the show method.)

Once your method is complete, you can use the interactions pane to test the method.

For an additional 20 points (for a total of 95 out of 100), write a second method called rotateColors in the Picture class that performs the following transformation:

And, as before, redisplay the image.

Finally, for an additional 5 points, find some images and then either rotate them or posterize them (or both).  Be creative and find images that have interesting and/or pleasing results.  You may want to write a copy of the posterize method (that you can name posterize2) so that you can experiment with different values for the thresholds and values defined above.  After creating a result, save the new posterized or rotated image to a new jpg file.  Be sure and use either good filenames or include a short text file to describe what you have done.  Some of the more interesting images you submit will be posted on the class webpage.

Turn In:

In your Assignment Inbox, turn in the modified Picture.java class definition in a folder named prog2.  Also in that folder, include both before and after jpgs from the last part.