[Edu-sig] Steps for making a Fractal with Python

Kirby Urner urnerk@qwest.net
Mon, 09 Jul 2001 00:26:44 -0700


Steps to get a fractal (Mandelbrot) with Python:

Used search engine to find:
http://pathfinder.scar.utoronto.ca/~csca57/PIL_python.html

Downloaded source code, saved as fractal.py, along with rainbow3.pal
to same directory.  rainbow3 is one of many palettes provided, and
effectively colorizes the grayscale fractal using im.putpalette(pal, 'RGB').

Had latest PIL (Python Imaging Library) installed earlier, from
http://www.secretlabs.com/products/pil/index.htm

In DOS box (WinME), entered:
D:\...> ..\python fractal.py "myfractal.gif" "rainbow3.pal"

(initial ..\ because python.exe is in directory above the subdirectory
where launching.  Got a warning about some PIL module using nested
scopes in a lambda, so added:

   from __future__ import nested_scopes

to the top of the copied fractal.py source code.  This fixed the
problem.

After a short time (fast computer), myfractal.gif was available for
viewing.  The picture resembles the one shown on the web page.

The source defines an Image then uses im.putpixel((i,j),value)
in a loop through all (i,j) image coordinates, to each of which
there corresponds a complex number, which feeds into a special
loop and either diverges or converges after n iterations.

Note:  I don't quite see why they coders import Tkinter.  If
I comment that out and import sys instead, it runs just fine.
Maybe there was some plan to display the GIF at the end.  As is,
you need to pull up your GIF in a standard viewer.

Kirby