Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MAT 2170 Laboratory 8: Julia Sets and Algorithms, Lab Reports of Computer Science

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

Pre 2010

Uploaded on 08/18/2009

koofers-user-ilt
koofers-user-ilt 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MAT 2170: Laboratory 8
Key Concepts
1. Developing algorithms
2. Writing and using methods
Instructions
Complete the Prelab (found at the back of this handout) before lab on Thursday.
Staple your completed Prelab to the front of your printouts to turn in next week at the beginning
of lab 9.
Exercises
1. (Page 172, Exercise 5, SliderProgram:Bullseye) Rewrite the original Target program to uti-
lize the createFilledCircle() method. Get the number of circles to be drawn from the slider,
with a range from 1 to 15. Be sure to include and use the constants OUTER RADIUS and IN-
NER RADIUS, and follow all instructions in the exercise. There is no need to use a pause in this
program the finished image is the goal. (Note: the slider program has been updated on the course
web site. If you are having trouble with re–running a slider program on your web site, please replace
the slider program for that project with the newer version, then replace the jar file.)
2. (Page 175, Exercise 11, Dialog Program: PrimeSolver) Create and test the isPrime() predicate
method, then extend this exercise to ask the user for a range, low to high, and determine all the
prime numbers in that range. These prime numbers are to be listed in a single dialog box.
3. (Julia Sets,DualSliderProgram:JuliaSet) You are to complete a program which produces a
graphical display of a fractal, or Mandelbrot set. A fractal is a function that maps coordinates to
values which we may then use to represent various colors. The method which will do this mapping,
JuliaColor(), is provided for you. The graphics window is to be divided into rows and columns
in the same way we created a checker board and other tilings of the graphics window. In this case,
however, instead of alternating block colors, the JuliaColor() method is used to determine the
color for each block.
In addition to completing the run() method, you must also complete the BlockCorner() and
ScreenToWorld() methods. BlockCorner(), when given the row and column of a block, is to
return the position of the block at the intersection of row and column. ScreenToWorld() is to
calculate the world region coordinate associated with the current block’s position in order to find
the corresponding Julia color.
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) = (x2y2+a, 2xy +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.
pf3
pf4
pf5

Partial preview of the text

Download MAT 2170 Laboratory 8: Julia Sets and Algorithms and more Lab Reports Computer Science in PDF only on Docsity!

Key Concepts

  1. Developing algorithms
  2. Writing and using methods

Instructions

  • Complete the Prelab (found at the back of this handout) before lab on Thursday.
  • Staple your completed Prelab to the front of your printouts to turn in next week at the beginning of lab 9.

Exercises

  1. (Page 172, Exercise 5, SliderProgram: Bullseye) Rewrite the original Target program to uti- lize the createFilledCircle() method. Get the number of circles to be drawn from the slider, with a range from 1 to 15. Be sure to include and use the constants OUTER RADIUS and IN- NER RADIUS, and follow all instructions in the exercise. There is no need to use a pause in this program — the finished image is the goal. (Note: the slider program has been updated on the course web site. If you are having trouble with re–running a slider program on your web site, please replace the slider program for that project with the newer version, then replace the jar file.)
  2. (Page 175, Exercise 11, Dialog Program: PrimeSolver) Create and test the isPrime() predicate method, then extend this exercise to ask the user for a range, low to high, and determine all the prime numbers in that range. These prime numbers are to be listed in a single dialog box.
  3. (Julia Sets, DualSliderProgram: JuliaSet) You are to complete a program which produces a graphical display of a fractal, or Mandelbrot set. A fractal is a function that maps coordinates to values which we may then use to represent various colors. The method which will do this mapping, JuliaColor(), is provided for you. The graphics window is to be divided into rows and columns in the same way we created a checker board and other tilings of the graphics window. In this case, however, instead of alternating block colors, the JuliaColor() method is used to determine the color for each block. In addition to completing the run() method, you must also complete the BlockCorner() and ScreenToWorld() methods. BlockCorner(), when given the row and column of a block, is to return the position of the block at the intersection of row and column. ScreenToWorld() is to calculate the world region coordinate associated with the current block’s position in order to find the corresponding Julia color.

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.

Finishing Up

When you have completed the Lab and all of the Prelab:

  1. Publish the programs to your web site
  2. Submit an electronic copy of the lab
  3. Staple the Prelab to the front of your printouts for all three projects and hand them in at the beginning of Lab 9.

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

  1. For Exercise 1, the Bullseye project (assume the named constants for the radii as given in the text):

(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.

  1. For Exercise 2, the PrimeSolver project:

(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