Python Script For Making Mandelbrots
Posted: April 7, 2007
This is my first attempt at Python :). I figured Mandelbrots would be fun since Python has a built in complex number type. If you'd like an explanation (and example images) of what Mandelbrots are, take a look at my Mandelbrot page here.
Related Projects @mikekohn.net
How To Run
From a command prompt, type: python py_mandel.py
If you'd like to change the image, edit py_mandel.py and change the parameters at the top of the file. You can also change the colors by editing the colors list.
To write out the BMP, I made a kohn_bmp class. It's capable of creating 24 bit color images and 8 bit grayscale. Feel free to use this class if you like in other programs as long as you don't remove my name, webpage address, email address, or copyright.
Python vs. Perl
So I decided to translate this code into Perl and see which one is faster. I did my best to make a 1 to 1 translation, so I think the two code bases are pretty similar. So on a 640x480 mandelbrot using my default coordinates of (-2.0,-1)-(1.0-1.0):
Athlon XP 1.8GHz - Gentoo Linux
Core2 Duo 2GHz - MacOSX Leopard on a MacMini
Well, this might not be the fairest test since most people aren't going to be using either of these two languages to compute math functions (altho I did find the built in complex number system into Python to be quite interesting.. Perl had something similar which I used here too, but I have a feeling from the results above that it isn't as optimized as Python). This test is just one more reason why I much prefer Python to Perl... well, other than the fact that the only thing that could make Perl more cryptic and tedious is if the language was programmed using morse code. ... --- ...
Copyright 1997-2018 - Michael Kohn