Math + Making

A student blog for Math 189AH: Making Mathematics at Harvey Mudd College

Drawing Fractile in PIL

Jackson Salumbides

By King and Jackson

The fractile we will be focusing on is the mandelbrot set fractile. According to Wikipedia, The Mandelbrot set] is a “two-dimensional set with a relatively simple definition that exhibits great complexity, especially as it is magnified. The set is defined in the complex plane as the complex numbers c for which the function fc(z) = z2 + c does not diverge to infinity when iterated starting at z=0, i.e., for which the sequence fc(0), fc(fc(0)), etc., remains bounded in absolute value. We assume that the sequence Zn is not bounded if the modulus of one of its terms is greater than 2”. The Mandelbrot set. MIT’s Dr. Kreiger has a YouTube video that elaborates on the Mandelbrot set.

As beginner programmers, drawing the mandelbrot set made a rewarding exercise that provided practice with loops and conditionals, and functional programming. Specifically, for this project, We will get more practice with the PIL library in Python. 

To make it a little more interactive, we explored a zoom-in feature, where we used a GUI, specifically, Python’s own 

The link shows the process we followed but with plain Python code(in our case, the PIL library). We will be using the recursive function shown:

We will be using PIL for image processing Tkinker for the Interactive user interface

To start we created a grayscale mandelbrot set fractile generator that did not have any zoom functions. The code begins by defining the mandelbrot function, which takes a complex number c and a maximum number of iterations as inputs. It iterates the function f(z) = z^2 + c, checking if the magnitude of z exceeds 2.

Without zoom functions, the beauty of the fractile was not visible.

After this,  we added a zoom function (using Tkinker) that redrew the fractile as if it was zoomed in every time the user clicked. Then, color was added using an iterative function that chose the code for the color based on the iterative step.

This is our final product. The more you click on a feature to zoom in, the more intricate features are revealed. 

Full code on GitHub

The Mandelbrot set is significant not only for its aesthetic appeal but also for its demonstration of the concept of “edge of chaos” in complex systems, where tiny changes in the initial conditions (the value of c) can lead to vastly different outcomes. It serves as a classic example of fractal geometry, exhibiting self-similarity and infinite complexity.


Leave a Reply

Your email address will not be published. Required fields are marked *