Gen's Mandelbrot Fractal Project

Explanation of the Project

This project is a GUI (graphical user interface, i.e., a program that opens in a new window) for drawing the Mandelbrot Fractal. The GUI frontend is written in Python and the backend (the calculation of the fractal) is written in C. Using CPython, the C backend communicates with the Python frontend to display the Mandelbrot Fractal (more information on the Mandelbrot fractal can be obtained here) or any of the other fractals that I have included in this project. The project was written with a Python frontend because Python is an optimal language to make a GUI for a project (it is quick and easy to make a GUI) and C is used for the backend because Python is not a good language for calculations. This is the third assignment for the Computer Science 206 class. This page is the required documentation for the project.

How to use the project

First off, you need to compile the C code. Thankfully, I have included a Makefile to do this, so type "make" in the command line to do so. Then, to run the program, type "python gui.py" in the command line. You will see the GUI interface, which should resemble this (click the thumbnail for a fullsize picture):



The leftmost line of entry boxes are the parameters for the Mandelbrot fractal. They are pretty straightforward: filename is the name of the file for the picture of the fractal, with the "Browse" button to browse the filesystem for a specific place to save the file. Width and height are the width and height of the picture, respectively. Offset X and Offset Y are how many pixels the fractal is moved in either the x or y direction. Scale is the magnification of the picture (a scale of 2, for example, would magnify the picture 2x a scale of 0.5 would magnify the picture to half size). Below these entry boxes are several radio buttons to choose the fractal to be generated.

Next to these entry boxes are the colored entry boxes for the foreground and the background. These are both RGB values from 0-255. Note that in order to use these color boxes, the "color" radiobutton must be pressed above these entry boxes. Otherwise, a black and white picture will be returned. Beneath the background and foreground entry boxes are two buttons, "execute" which displays the fractals according to the parameters, and "quit" which quits the application.

To the right of the background and foreground entry boxes is a big white box, or canvas. Here is where the fractal will be drawn according to the user specified parameters.

The Fractals

Currently, there are 5 fractals available. There is the Mandelbrot Fractal, the Newton Fractal, the Burning Ship Fractal, the Julia Set and the Star Fractal. The Mandelbrot fractal is the classic Mandelbrot with a rudimentrary coloring scheme. The Newton Fractal is the classic Newton fractal but with a different coloring scheme than normal. For one of the roots of the fractal, it is colored using an alternating scheme (see the picture below) The Burning Ship Fractal is a classic fractal with a basic coloring scheme. It does not look like a fractal at first glance but when you zoom into any of the small "dots" that pepper the screen, they are replicas of the bigger image. Also, each of the "holes" in the dots represent a fractal as well (see the Burning Ship Artistic Piece at the bottom of the screen). The Julia set is the quadratic version with a basic coloring scheme. The Star fractal is officially called the "Not-Z" fractal. The "Not-Z" fractal class is a large class of fractals where the screen is divided into 4 distinct areas. Because of the way the star fractal is defined, it takes in only one color instance-the foreground, which is the primary color. The secondary color is made as the opposite of the primary color (ie, green and purple). Examples of each of the fractals made with this application are shown below (this is the output). Click on each of the thumbnails for the full size image.

The Mandelbrot Fractal
Grayscale Mandelbrot
Color Mandelbrot
W:800 H:600 X:-180 Y:0 S:1 W:800 H:600 X:-190 Y:0 S:1
Foreground: R:100 G:10 B:100
Background: R:100 G:110 B:10
The Newton Fractal
Grayscale Newton
Color Newton
W:600 H:600 X:0 Y:0 S:1 W:600 H:600 X:0 Y:0 S:1
Foreground: R:130 G:10 B:3
Background: R:10 G:130 B:10
The Burning Ship Fractal
Grayscale Burning Ship
Color Burning Ship
W:600 H:600 X:-92 Y:100 S:.84 W:600 H:600 X:-92 Y:100 S:.84
Foreground: R:40 G:10 B:3
Background: R:130 G:250 B:60
The Julia Set
Grayscale Julia Set
Colored Julia Set
W:600 H:600 X:0 Y:0 S:0.86 W:600 H:600 X:0 Y:0 S:0.86
Foreground: R:40 G:10 B:3
Background: R:130 G:200 B:60
The Star Fractal
Grayscale Star Fractal
Colored Star Fractal
W:600 H:600 X:0 Y:0 S:1 W:600 H:600 X:0 Y:0 S:1
Foreground: R:90 G:10 B:30
Background: R:130 G:200 B:60

Source Code

There are 3 files, the C backend (which is named mandel.c), the Python frontend (it is named gui.txt because the browser will try to run it as Python embedded code, you must rename it to "gui.py" upon succesful download) and the Makefile to compile the C file. Note that this code is optimized to run in the CS Labs at Trottier where Python.h is installed. It may not work on other machines either because CPython is not implemented, or it is in a different directory. Other problems may arise, so it is highly reccommended to run the program on the CS Lab Machines (I used lab7-20).

Here is a zip file with everything needed to compile and run the program (Makefile, gui.py, mandel.c):

Bugs and/or Shortcomings

The only bug I could find is the star fractal only being able to implement one color (the foreground color) but this is the way it is defined. Also, the star fractal is an extra fractal I included more for the artistic bonus. The other four fractals (Mandelbrot, Newton, Burning Ship and Julia Set) make up the 4 fractals for the extra credit portion of the project. I did not implement defensive programming for this application. Therefore, if the user enters a letter where a number is supposed to be inputted, the program will return an error. Likewise, if the user does not enter anything, the program will return an error. This is the only shortcoming I can discern. Another possible shortcoming is the speed of the program for large images. It takes around 30 seconds for a 600x600 image, but this seems like the norm when I compared it to my classmates.

Length of the Assignment

This assignment took me roughly 10 hours spread over several days to implement the mandelbrot Fractal. The other fractals took about 2 hours each to implement. This html file took me roughly one hour to complete (most of the time spent on making images from the software for the examples).

Artistic Pieces

The following are some pieces I created using this application:


W:600 H:600 X:-360 Y:670 S:28
Julia Set (Color)
W:600 H:600 X:298 Y:298 S:10
Star Fractal (Color)
W:600 H:600 X:0 Y:-299 S:300
Newton Fractal (Color)
W:600 H:600 X:-820 Y:110 S:13
Julia Set (Color)
W:600 H:600 X:0 Y:-299 S:300
Newton Fractal (Grayscale)
W:800 H:600 X:1300 Y:0 S:9
Mandelbrot Fractal (Color)
W:600 H:600 X:115 Y:880 S:4.2
Julia Set (Color)
W:600 H:600 X:-2040 Y:1550 S:7
Burning Ship Fractal (Color)

Update (1/17/2007)

The Star Fractal won the artistic bonus for the Fall 2006 CS206 class. It was featured on the CS homepage (not anymore). You can view the other finalists here.



© Gen Kazama December 2006