RSS Feed

RSS

Comments RSS

ASCII Mandelbrot Fractal – as a Python CGI

Here is an example of a Python CGI that I have running on my SDF.org website.  It generates a ASCII Mandelbrot Fractal and allows for the user to change and zoom in the field of view.  Granted, it is very low resolution being ASCII, but the main purpose was to demonstrate the use of Python for CGI purposes on SDF.org.   (FOR FURTHER EXPLORATION):   Since the SDF.org server Python package (v 2.6.5) has the PIL (Python Image Library) available, I can see no reason that true binary images of Mandelbrot fractals might not be produced and displayed on as pictures on the web page.  UPDATE:  As suspected, creating true graphical Mandelbrot fractals did in fact work out well.   Here is a link to a Python CGI that uses PIL to create the images.  Graphical Mandelbrot CGI

Benoit Mandelbrot dies, aged 85

As regular readers of my blog will know, I have been a fan and enthusiast of the mathematically derived images know as Fractals for many years after having been first exposed to the concept in an issue of Scientific American in the Mathematical Recreations column. I began writing programs to generate these beautiful images and even today still tinker around with these. Benoit Mandelbrot, the man who started it all and for whom the iconic fractal image is named, has passed way at age 85. The impact of his work went far beyond just some pretty pictures.   He fundamentally added to our understanding of nature and brought order to what had always been thought to have been random chaos in complex systems such as meteorology and reaching even into the fields of economics and the social sciences. His work was the genesis of what we now know as Chaos Theory. The impact of the revelation that Benoit Mandelbrot brought to human understanding of the world around us and of complex systems has already been felt.  It will continue to be felt as we delve deeper and deeper into the exploration of nature.  We are now assured that there will always be more beauty to be found as the self-similar and endlessly complex world unfolds before us. To me, Benoit Mandelbrot opened a door to us into the beauty and complexity of nature and into the mind of nature’s Creator. He will be missed.

The Mandelbrot Set

Python – very graphic! cont.

I must say, this has been a great experience trying out some graphical programming in Python. I looked at two different graphics packages for this exercise, Tk and PyGame. While Tk is very good for many graphical interfaces, particularly GUI, it did not provide what I needed most – the ability to do pixel by pixel plotting. Tk, does provide a “way” of doing it using the PhotoImage class, but it was rather cumbersome and felt like a workaround. So, I explored PyGame. It is a mature third party Python library specifically designed for graphical game design. It had exactly what I needed and was very straight forward. I simply wanted to create a display screen area and plot colored pixels to it corresponding to Mandelbrot Set. PyGame gave me exactly what I needed. Here is a series of pictures of the Mandelbrot Set. First, the full set. Second, an image zooming in on a region in the set. Third, zooming in even further. The fascinating thing about the Mandelbrot Set, and all fractal objects, is the the more you zoom in, the more detail you see – not less.

The Mandelbrot Set

Zooming in on the Mandelbrot set #1

Zooming in on the Mandelbrot Set #2

Python – very graphic!

Now that I have got the basics down of using Python to do some tasks at work and some programming for my own enjoyment (i.e. the MazeGame).  Now it is time to learn how to get graphics other than a GUI working for me.   For this, I have decided to write a simple program to generate a Mandelbrot set fractal.  This is one of the first major programs I ever wrote, way back in the late 1980s.  Time to revisit it in Python.   I am going to try out the Pygame library for the graphics on this program.

Incredibly deep fractal zoom

Mandelbrot Fractal Set Trip To e214 HD from teamfresh on Vimeo.

The final magnification is e.214. Want some perspective? a magnification of e.12 would increase the size of a particle to the same as the earths orbit! e.21 would make a particle look the same size as the milky way and e.42 would be equal to the universe. This zoom smashes all of them all away. If you were “actually” traveling into the fractal your speed would be faster than the speed of light.

I have been fascinated with fractals ever since the 1980’s when I was exposed to them in an issue of Scientific American in the Mathematical Recreations column.  I was a young programmer then and would devour the pseudo-code and algorithms found in that magazine.  I began working on writing my own Mandelbrot fractal program and with joy saw it appear on my screen. This was on an IBM XT 8088 clone with a Hercules graphics card and amber screen, so all I had was amber grayscale images, but it was still a thrill!  This was in such computationally ancient times that I had to write my own graphics primitives in assembler for use in the BASIC and Pascal programs because the graphics libraries were not available for my system configuration.   My programs took many hours to produce a single image on that old system.  The the video you are watching here demonstrates how far the science, art, and hardware available to produce these beautiful and intricate images has come.  Bravo!

adapted from the kottke.org blog