Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Assignment 1: Mandelbrot Set in Java COMP 144 Programming Language Concepts Spring 2004 Assignment 1: Mandelbrot Set in Java Due Date: Monday Jan 26 Here is more information about the math in computing the Mandelbrot set in the complex plane. Description Your task in this assignment is to compute and visualize the Mandelbrot set. This set is the result of studying the convergence of the iterative function xt+1=xt2+c with x0=0+i0=0. This function is defined in the complex plane, i.e. xj for j=0,1,... and c are complex numbers. A point c is said to belong to the Mandelbrot set if the value of xt as t goes to infinity is bounded. The following figure shows this set: Each of the black points represents a value of c that belongs to the Mandelbrot set. In the previous figure, the real part of each of the points is placed on the x-axis, while the imaginary part is placed on the y-axis. In spite of its simple definition, the structure of this set is strikingly complex. In practice, we can explore this set in the complex plane by evaluating the values of xt after some number of iterations (e.g. t=30) and comparing |xt| with 2 (it is possible to prove that if |xt| exceeds 2, then the sequence of xt for t=0,1,... grows to infinity). A particularly attractive way of plotting this set is to color each point in the complex plane according to the number of iterations that it takes to determine whether the point belongs to the set or not (i.e. value of t the first time xt > 2). The following figures show two sample visualizations: In this assignment, you have to write a Java program that computes and visualizes the Mandelbrot set. The visualization should use color as in the two figure above, but you are free to choose the color scheme, as long as it remains informative. The program should be invoked with: java Mandelbrot a b c d After this, your program should create a window with a visualization of the set in the subplane with (a+ib) as its upper left corner and (c+id) as its lower right corner. The resolution should be at least 200 by 200 pixels (i.e. evaluate the function for at least 40,000 points.) Hints Complex Numbers Remember that a complex number consists of the pair (a+ib), where a and b are real numbers. a is known as the real part, and ib as the imaginary part. The absolute value of a complex number is given by |(a+ib)|=(a2+b2)1/2 and the following rules are used to add and multiply complex numbers: (a+ib)+(c+id)=(a+c)+i(b+d) (a+ib)*(c+id)=(ac-bd)+i(ad+bc) Graphics in Java You can find numerous tutorials on how to draw and create images in Java. For instance, the official Java Tutorial gives a good introduction to the topic in http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html If you need help working with frames, check http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html Understanding Your first Swing program section is enough for the basic solution of this assignment. Extra Credit You can extend your solution in several ways: Include text boxes in the visualization window, so you can change the boundaries of the subplane without exiting the program. Allow the user to zoom in and out using their mouse when viewing the set. Optimize the naive algorithm and compare the computation times before and after the optimization(s). Submission This assignment is due on Jan 26 (during the first ten minutes of class). Late assignments get 25% off each day they are late (e.g. Jan 26 after 12:40 PM, -25%; Jan 30, -50%). Your submission will be electronic. Your electronic submission will be an e-mail sent to wluebke@cs.unc.edu with the subject COMP 144 Assignment 1 Submission and a single .zip file attached to it. This file should have the following content: Full source code. If you have written an applet, include an HTML page that will load and run the applet. A clear description of the process I should follow to compile and run the program. A short overview of your solution that describes the design of the program and the extend to what you have solved the problem. I will compile the program using Sun's SDK v1.3.1_02 (see http://java.sun.com/j2se/1.3/) only. You can develop you program with any Java programming environment, but you must make sure it compiles and runs under SDK 1.3. SDK 1.3.1 It is very easy to install this package, since it comes as a Windows installer. You can find very detailed information on how to compile and run Java programs with SDK at http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html In addition, you will probably want to change your DOS PATH variable, so you do not have to type the directory where the SDK executable is located each time you compile or run a Java program. See http://java.sun.com/j2se/1.3/install-windows.html#Environment for more details. Grading I will grade both the quality of the source code (design and documentation) and the output. I will not grade programs that do not compile. Collaboration is encouraged, but you cannot share source code. Honor Code applies to this program. Please, read http://www.cs.unc.edu/Admin/Courses/HonorCode.html for more details.