CSE 131 Module 4: Encapsulation


Bridge: Iteration and Encapsulation

Julia sets: fractal images


Fractals are mathematical models that can create seemingly complex drawings from very simple specifications. Because they are not easily bored, computers are well-suited to iterative tasks. You will use iteration in this lab to compute a fractal drawing. This lab emphasizes how computation can be applied with relative ease and speed to create what would take a human much longer to accomplish.

Before Starting:

  1. Update your workspace and look for the julia package. To run the program, run Main as a Java application.
  2. Please read over the entire document before you start. Really. It will save you time in the long run.
  3. Take a look at the JavaDoc for this lab.
    The JavaDoc for this lab is the main mechanism for communicating the lab's design to you. You must implement the objects that are described in the documentation, and JUNIT tests are provided to help you determine if your code is working properly.
  4. If you are interested, see the wallpaper a student made from this lab. You can change constants and colors to get different patterns.

Background Information:

Fractals are an amazing mechanism for describing complex systems in terms of simple and recursive components. The idea of fractals in the complex plane (where the x coordinate is real and the y coordinate is imaginary) dates back to 1918, when Gaston Julia began research that characterized Julia Set fractals. In 1979, Benoit Mandelbrot defined a map over Julia sets that reflected the expense of computing a specific point in the set. Such maps generate interesting patterns, and we will in a sense reproduce Mandelbrot's work in this lab. Since Mandelbrot's original work, computers have become faster and Java has made programming them easier. Thus, our renditions will be more aesthetically pleasing (and won't take overnight to render either). Search here (using Google) to find some pages with more background information.

Problem statement: Drawing a Julia Set

This lab involves computation over some points of a complex plane. Recall that a complex number has two components: a real and an imaginary part. For each complex point c that we want to display, we compute the function rigor(c) as follows.

Pseudocode for rigor(c):
z = -0.7795 + 0.134 i
iters = 0
while abs(c) < 2 and iters < maxIters
     c = c*c + z
     iters = iters + 1
end while

return iters
In other words, rigor(c) is the number of iterations that it takes to compute the value at c. The value of maxIters is arbitrary, but let's assume for now that 100 iterations are allowed for the computation. The function abs(z) computes the distance of z from the complex point (0,0).

To show complex numbers on an x-y axis system, let us assume that the real component of a complex number is registered on the x-axis; the imaginary component is thus registered on the y axis. If we apply the above computation over the complex plane as x ranges from -2 to 2 and y ranges from -2i to 2i, we obtain the following picture:

(-2, 2i)(0, 2i)(2, 2i)
(-2, 0i) (2, 0i)
(-2, -2i)(0, -2i)(2, -2i)
Figure 1: Initial display

Zooming around

What is really interesting about a fractal drawing is that one can dive into the drawing and discover ever increasing detail. Below you see the results of zooming into the picture.

(-1.6, -0.5i) (-0.6, 0.4i)
(-1.6, 0.5i) (-0.6, 0.5i)
(-1.51755, 0.063544i) (-1.51210, 0.063544i)
(-1.51755, -0.0690i) (-1.51210, -0.0690i)
Zoom in on left part of picture Another zoom in on left part of picture


Demo and submission

At a predesignated time (not during ordinary labs or studios), you may demo this bridge to a TA. He or she will mark down the demo and the SVN repo number of your julia package files.