Sie sind auf Seite 1von 4

Intro Ex5: Multidimensional Arrays

Deadline: December 8, 2011 at 20:00.

Overview
This exercise has two related parts; in the first part you will practice the use of multidimensional arrays by implementing a class for representing color images. In the second part you will graphically explore the Mandelbrot set. Overall you need to implement two classes according to their given API: 1. RGBImage, which uses the RGBColor class. 2. Mandelbrot class, which uses the Complex class and RGBImage classes. To avoid interference from bugs and possible incompatibilities with your implementation from ex4, we provide you our own RGBColor (API) and Complex (API) classes (used by the school solution). Please use these provided classes and not your own classes. The classes are available in the intro.ex5 package and you may import them using import intro.ex5.RGBColor; import intro.ex5.Complex;

RGB Image
In this part of the exercise you will use a two-dimensional array of RGBColor objects to represent a color image. Each point in the image is called a pixel (picture element) which represents the color at a single coordinate.

The RGBImage class


Implement the RGBImage class according to its API, using a two-dimensional array of RGBColor objects to represent the image. For indexing pixels in the image we use the conventional way: In an image with n rows and m columns, the rows are numbered 0...n-1 from top to bottom, and the columns are numbered 0...m-1 from left to right. Note that the API contains only the prototypes of the class's public methods; you should add private data members and methods as necessary. Make sure to protect the encapsulation of your classes: it should not be possible to change an object's internal state except through its public methods. For example, the RGBImage method setPixel should not save a reference (make an alias) to the given RGBColor object, rather you should make a copy of it (do you understand why?).

Error handling
Use the intro.ex5.ErrorPrinter class to handle invalid parameters for the RGBImage class. Whenever the API says to "raise an error," call the ErrorPrinter.error method, and pass it a short message explaining what the error was. This method will print your error message and then terminate the program.

The Mandelbrot Set


In the second part of the exercise you are required to use three classes: our implementation of the Complex and RGBColor classes from ex4 and your own implementation of the RGBImage class from the first part of the exercise, to graphically explore the Mandelbrot Set. The Mandelbrot Set, as defined in ex4, is a set of points in the plane of complex numbers, whose escape time is infinite. The boundary of this fractal set is very elaborate, revealing progressively finer self-similar detail under increasing magnifications.

The Mandelbrot class


The Mandelbrot class represents a rectangular region of the complex plane as a color image, where the color of each pixel (corresponding to a point in the complex plane) is determined according to the escape time of the complex point from the Mandelbrot radius. The complex numbers contained in each Mandelbrot object are determined according to the size of the rectangular region, its resolution and the complex number in its top left corner. You should implement the Mandelbrot class according to its API.

School provided classes


We provide you with the MandelbrotViewer class (API and code), which can be used to graphically view the results of the Mandelbrot class which you implement. It uses intro.ex5.ImageViewer, if you are interested you can look at its API and code. The program is run with three command-line arguments:

java MandelbrotViewer height maxIterations magnifyFactor


for example: java MandelbrotViewer 400 200 4 See the API for a detailed explanation of the command line arguments. We assume the command-line arguments are always legal.

User interaction
The user may zoom in on a certain area by clicking the right mouse button. This will cause the image to be magnified by a constant factor, and re-centered around the selected point. The user may also shift the area displayed (without changing the magnification) by pressing and dragging with the left mouse button. This will cause the image to be redrawn so that the point where the user pressed the button moves to the point where the user released the button. Note: all of the interaction is handled by the classes that we provide you. Your task is only to correctly implement the classes RGBImage and Mandelbrot, according to the provided API.

Testing
As in previous exercises, we provide you with automatic testers we'll use on your solution. You may run them in one of the following ways: Run the command ~introcsp/bin/testers/ex5 ex5.jar from the shell. Download the file www.cs.huji.ac.il/~introcsp/testing/ex5testing.tar.bz2 (or .zip) and follow the instructions in the TESTING file.

Submission
Submit a jar file named ex5.jar containing the files RGBImage.java, Mandelbrot.java and README.

Before you submit...


Remember to use constants where appropriate and refrain from duplicating code. Make sure to thoroughly test all the RGBImage methods (not just those used in the Mandelbrot program). Don't forget to document your code (including javadoc), follow all course coding style guidelines, and verify that the e-mail you receive upon submission indicates that everything is well.

Das könnte Ihnen auch gefallen