



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Laboratory 8 for mat 2170, which covers developing algorithms, writing and using methods, and creating julia sets. Students are required to complete various exercises, including rewriting a target program, creating and testing a prime number solver, and producing a graphical display of a fractal. Instructions and explanations are provided.
Typology: Lab Reports
1 / 6
This page cannot be seen from the preview
Don't miss anything!
How It Works
To every point (a, b) in the plane we can associate a function of two variables referred to as the Julia map for (a, b), denoted by Fa,b and described by the formula
Fa,b(x, y) = (x^2 − y^2 + a, 2 xy + b).
The Julia set for (a, b), denoted by Ja,b, is the collection of all points in the plane from which you can start and never get too far away from the origin by repeated iterations of Fa,b. These sets turn out to be bizarre fractal sets. Different choices of (a, b) often give rise to quite exotic sets Ja,b.
One way to picture these is to color points in the plane according to how many iterations it takes, starting from that point, to get outside a threshold circle (usually of radius 2). The points that don’t get out within a certain, preset number of iterations are the ones that are in the Julia set and are colored black. The main idea in this problem is to map each block in the graphics window to a corresponding point in the world region that we are representing. This is accomplished by the ScreenToWorld() method. It is passed a GPoint representing a point in the window, and it returns a GPoint representing the coordinates of the corresponding point in the world region. For each block in the grid, you:
(a) find its upper left corner position (using BlockCorner()) (b) find the corresponding point in the world region (using ScreenToWorld()) (c) find the color this point (block) should get (using JuliaColor()) (d) draw a block of the correct size, location, and color to represent the Julia map
The method Norm() is used by JuliaColor(), and the method NextPoint() is just the Julia map mentioned earlier.
Steps to Complete
(a) Create a new project, JuliaSet, add the acmLibrary to it, create two new, empty java files as usual and copy the java code for the DualSliderProgram and the JuliaSet classes from the course web site. (b) Locate the implementation of the BlockCorner() method (below run()). You are to complete this method so that given a row and column (as a GPoint parameter), BlockCorner() returns a GPoint indicating the position in the graphics window of the block at row and column. Add statements to the main program to test your code by filling the graphics window with cyan blocks with black borders. Make use of the constants which have been provided in the program skeleton. Now build and run the program, checking to see that everything works so far. Correct any errors in this method before proceeding. (c) You are already nearly finished. The last step will be to use the JuliaColor() function to determine the color of each block before it is drawn. To do this, you must complete the ScreenToWorld() method, used to scale a graphics window coordinate into a world region co- ordinate. The resulting GPoint should then be sent to the JuliaColor() method to determine the color of the current block.
When you have completed the Lab and all of the Prelab:
57 while ((Norm(Z) < Threshold) && (Iterations < MaxIterations)) { 58 Z = NextPoint(Z, JuliaTerm); 59 Iterations++; 60 } 61 62 if (Iterations >= MaxIterations) { 63 return Color.BLACK; 64 } else { 65 switch (1 + Iterations % (MaxColors - 1)) { 66 case 1: 67 return Color.BLUE; 68 case 2: 69 return Color.CYAN; 70 case 3: 71 return Color.GREEN; 72 case 4: 73 return Color.RED; 74 case 5: 75 return Color.YELLOW; 76 case 6: 77 return Color.ORANGE; 78 case 7: 79 return Color.MAGENTA; 80 case 8: 81 return Color.PINK; 82 case 9: 83 return Color.WHITE; 84 case 10: 85 return Color.DARK_GRAY; 86 default: 87 return Color.GREEN; 88 } 89 } 90 } 91 92 // the position of the world point corresponding to the screen point 93 public GPoint ScreenToWorld(GPoint p) { 94 // replace this code 95 return new GPoint(0.0, 0.0); 96 } 97 98 // position of block at row, col 99 public GPoint BlockCorner(int row, int col) { 100 // replace this code 101 return new GPoint(0.0, 0.0); 102 } 103 }
Lab 8— Prelab Name: Detach this page, staple printouts for all programs from Lab 8 to it, and turn in at the beginning of Lab 9
(a) Give the statements which will determine the coordinates (x and y) for the outer circle when the target is centered in the window:
(b) Give the statement which will calculate deltaR, the change in radius from one circle to the next, given the slider value n:
(c) Develop an algorithm which satisfies the conditions imposed in the write up and utilizes the method createFilledCircle(). You may assume the objects created above are available.
(a) Fill in the table of testcases below to give yourself a test suite. When your program is finished, complete the table with the actual results obtained from program execution:
low high Expected Results Actual Results 1 10