Skip to content

stratzilla/fractal-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fractal-generator

This is a simple OpenGL fractal generator/visualizer. Some fractals are defined which are then displayed using OpenGL with zooming capability.

Fractals

Here, fractals are defined by set theory and limits. The equation used is below:

Where is the maximum number of iterations performed on . Each iteration is defined by an arithmetic expression describing the relationship between and , which is defined in terms of complex number arithmetic.

The superior limit of this iteration will consider points in the fractal set if their iterations remain bounded after the th iteration. Points which pass this test are within the set, with all others some distance from the set (used for coloring). was chosen to be the bound as it visualized well on a complex plane with real and imaginary axes both of [-2.0, 2.0].

Consider : all points in the plane are within the set. With , less are within the set, and so on until the shape of the set is realized. A very large will render the fractal set with higher precision but may be difficult to see as points become "infinitely" thin; contrastingly, a very small will render the fractal set with very little granularity and is overall an inaccurate render.

Suggested use case scenario is as it's a good balance between clarity, visual pleasure, and of course execution time.

Supported Fractals

Included are ten fractals, the first three have canonical names and the other seven are found through experimentation. The canonically named fractals alongside their iterative arithmetic is below:

Mandelbrot Set

Julia Set

  • is some constant, here defined as

Burning Ship Set

You can experiment with other fractals by editing Set.cpp: within Set::iterate() you can define the arithmetic expression which determines the set. Using a subset of complex number arithmetic, you can define new fractals. Available arithmetic operations are:

  • neg() on a complex number returns
  • inv() on a complex number returns
  • abso() on a complex number returns
  • standard operators +, -, * and ^ will function as expected
  • ^ only works with integer as second operand

For example, to get , you would hardcode in (z^3).neg() + z^2 + c, etc.

Dependencies

  • Freeglut
  • Freeimage
  • C++0x or later
  • gcc
  • X11 or other window manager

Execution

# Using included script:
$ ./fractal-generator.sh <arg>
# Or alternatively, manually compile and run:
$ g++ src/*.cpp -O2 -lGL -lGLU -lglut -lfreeimage -lX11 -std=c++0x -o fg
$ ./fg <arg>

<arg> is the maximum depth (number of iterations) used to define fractal within the range [32, 4096]. Higher is slower but shows higher fidelity of the fractal set. This is the from before.

CLI will appear on execution detailing controls. 1 through 0 will cycle between fractals, r to reset, s to save screen capture to parent directory. Use mouse buttons to zoom in and out.

Example Outputs

L-to-R: (z^2 - z^3) + (-0.372 + 0.519i), z^2 + c, z.inv().neg()^2 + z, z^2 + (-0.835 - 0.232i). More examples in img/. These images found using depth of 64.

Future

It is painfully trivial to add more fractals to the system, but this requires hardcoding. A truly generalized fractal visualizer should parse user input (eg. a string) into an arithmetic expression which defines the iteration for the fractal set. Perhaps in the future I can implement this.