CONTENTS

Home
Updates
Software
Electronics
Music
Resume
Contact


YouTube
Twitter
GitHub
LinkedIn


Python Script For Making Mandelbrots

Posted: April 7, 2007

Introduction

This is my first attempt at Python :). I figured Mandelbrots would be fun since Python has a built in complex number type. For an explanation (and example images) of what Mandelbrots are, take a look at my Mandelbrot page here.

Related Projects @mikekohn.net

Mandelbrots: Mandelbrots SIMD, Mandelbrot Cluster, Mandelbrot MSP430

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
Python 2.4: 1 minute 5.23 seconds
Perl 5.8.8: 94 minutes 2 seconds

Core2 Duo 2GHz - MacOSX Leopard on a MacMini
Python 2.5: 23 seconds
Perl 5.8.8: 49 minutes 13 seconds

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. ... --- ...

Download

py_mandel-2008-03-05.tar.gz
py_mandel-2008-03-05.zip



Copyright 1997-2024 - Michael Kohn