Python and Fractals


Slowly but surely I have been learning more of the programmatic side of computing. First was the extreme basics with HTML and CSS, next came MEL, and now I have reached Python. I have attempted to learn Python a few times in the past but a combination of heavy schedules and lack of commitment caused those attempts to fail quickly. But not this time. I am making noticeable progress and even have work to show for it.

Of course, being that I am still an artist at heart my application of this newfound skillet is predominantly graphical in nature. Case-in-point, my latest project. In order to better learn both syntax and logic (and because I have always wanted to) I am writing a fractal generator. Using iterative mathematical operations on complex numbers I can create intricate and infinitely complex images.

So far my script can generate the famous Mandelbrot set in any size using user-defined colors. The script works by assigning each x,y coordinate in my image to a coordinate on the complex plane. It then iterates the classic Z(n+1) = Zn^2 + C until the resulting complex coordinate falls outside of a circle with a radius of 2. Then a pixel (in a user-defined color) is created with a opacity corresponding to the number of iterations that were required. If the maximum specified number of iterations is met and the number still hasn’t exceeded the bounds of the circle, the pixel is given 100% opacity and it’s color is set to the second user-defined value. In layman’s terms, this means that points that fall into the definition of the equation are one color and those that don’t are given a different color that fades out the further they are from being included. Here’s an example of a Mandelbrot fractal I generated with color1 as red and color2 as blue:


In the future I hope to add a number of features such as:

  • Other types of fractals such as Julia sets
  • A web-based interface for creating and downloading fractals
  • Option to blend between colors (instead of opacity) to visualize iterations
Python and Fractals

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s