Home : Course Map : Chapter 11 : Java : Tech :
Fractal Algorithms
JavaTech
Course Map
Chapter 11

Introduction
Image Class
Image Loading
  Demo 1 Demo 2  
Pixels/Transparency
  Demo 3
Pixel Handling
  Demo 4  
Demo 5
Exercises

    Supplements
Java 2D Imaging
BufferedImage
Creating Buf.Image
Pixel Handling
  Demo 1 Demo 2
Filters
  Convolutions
     Demo 3
  AffineTransforms
     Demo 4
  LookupTable
     Demo 5 Demo 6
  Rescale
     Demo 7
  Color Conversion
     Demo 8
  Custom
     Demo 9
Exercises
Java Adv Imaging
AWT Flicker:
  Override Update
     Demo 1  Demo 2
  Clipping
     Demo 3
  Double Buffer
     Demo 4

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

Fractals offer a fun and interesting way to practice Java graphics and image making. In this section we briefly introduce the basics of fractals and discuss four particular fractal generation algorithms.

We provide two fractal demonstration programs that display patterns generated by these algorithms. The demos differ in how they display the fractal patterns: Demo 1 invokes the drawLine() method in Graphics for each point in a fractal pattern. Demo 2 modifies the pixels of an image and then draws the pattern with a single invocation of the drawImage() method.

The theory and applications of fractals have developed into a huge area of mathematics and computer science. See the References below for more extensive tutorials and examples.

Fractals

A fractal pattern looks the same whether you zoom in or zoom out. The basic characteristics of the pattern remain the same regardless of the scaling of the dimensions. This type of scale invariance for a pattern is referred to as self-similarity.

A famous example is a coast line. Whether looking at a particular coast from a satellite, from an airplane, or standing at the seashore, the edge always has the same irregular, jaggy, rough profile; only the absolute lengths of the jags change. (See the figure at Fractals Unleashed.)

There are many ways to generate fractal type patterns. For example, symmetrical geometrical fractal patterns can be created by interative application of a base-motif rule in which each segment, i.e. the base, of a geometrial figure is replaced by a motif shape and then the process is repeated on the resulting figure, and so forth. Examples include the Sepinski Triangle and Koch Snowflake.

Thus the key concepts for generating a fractal pattern are iteration and recursion. In a recursive algorithm, the output of a process is fed back in as the new input to the process.

For our demo programs we generate fractal patterns by iteratng a simple function such as

y(x) = x2 + c

The output y is fed back in as the new x value and the process repeated, i.e. recursed. The sequence of y values produced by this iteration is called the orbit of x0. If we start from a given x0 and for each interation y remains the same, then x0 is called a fixed point. If instead y goes off to infinity, then x0 is said to have an orbit that escapes.

If the values chosen for x0 in a given region always end up with y converging to the same point, then that point is called an attracting fixed point or attractor. That region is called a basin of attraction for the attractor.

This seemingly simple recursive process can generate amazingly complex patterns that display self-similar behavior. Here we described four such algorithms used in our demonstration programs. (We follow the general procedures given by ref. Mak for each of these).

Bifurcation

For the function given above,

y(x) = x2 + c

we selected a c value and examine the orbit for x0 = 0. We the select another c and repeat the process. The horizontal axis corresponds to c and the vertical axis to y. For a given c , i.e.column, the function is iterated for a fixed number of times. Before plotting them, a given number of iterations are skipped so as to reach the asymptotic behavior of the orbit. Then the y values are plotted for each of the remaining iterations.

Such an algorithm will generate a pattern where the orbits split, or bifurcate, and display holes in the pattern. Looking at smaller scales, the patterns will display the same behavor, illustrating the self-similarity feature of a fractal.

Julia Set

The function is similar to that given above except that the variables are complex numbers,

y(z) = z2 + c

where

z = x + yi
c = cr + cii

For the demonstration program, the user enters a give c value or uses the default. For each x,y point over the area displayed, the orbit is determined starting from z = x + yi. If the orbit escapes, a gray point is displayed at x,y . Otherwise, the RGB values of the color are chosen according to the magnitude of the final z after the interations are finished.

Julia Set via Newton's Method

In the Chapter 3: Physics we discussed Newton's method for determining the roots of a function. This involved an iterative process as well.

For the example here, we use the complex function

y(z) = z3 - 1

for which Newton's method leads to the iteration formula

z - (z2 + 1)/(3 * z2)

Three roots are found: 1, -0.5 + (sqrt(3)/2)i, -0.5 - (sqrt(3)/2)i

For the demonstration program, each x,y point over the area the iteration formula starting from z = x + yi. A color is plotted at the x,y point that depends on which of the three roots the process converged to.

Mandlebrot Set

This algorithm begins with the same function as for the Julia Set case. The function is similar to that given above except that the variables are complex numbers,

y(z) = z2 + c

where

z = x + yi
c = cr + cii

However, in this case we vary c. That is, for cr,ci we start from z = 0 + 0i and examine where the resulting orbit. We then plot a color at the point cr,ci that depends on the orbit. Escaped values become a gray whose shade is proportional to the number of iterations before the orbit exceeded the escape limit. For the unescaped cases, the RGB values depend on the magnitude of the final z value.

References & Web Resources

 

Most recent update: June 25, 2005

              Tech
Fractals
Fractal Drawing
   Demo 1
Fractal Draw Code
Fractal Images
  Demo 2
Image Processing
  Demo 3
Histogram Image
  Demo 4
Exercises

           Physics
Calibration/SysError
SimWithCal/SysErr
  Demo 1
Analysis
  Demo 2
Examples

Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.