DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Mandelbrot Set

Introduction

The Mandelbrot set is a mathematical set defined from a function, similar to and related to the Julia set. However, the Mandelbrot set is more widely know.

Finding Points in the Mandelbrot Set

For our purposes, this is a good enough definition of the Mandelbrot set for a function (x’, y’) = f(x, y, a, b), where (x, y), (a, b) and (x’, y’) are the coordinates of points in the 2 dimensional plane.

Take a point (a, b). Using x0 = 0, y0 = 0, a, and b as input to f(x, y, a, b), we receive a new point from the function.

x1, y1 = f(x0, y0, a, b)

Repeat that process by using the output of the previous call of the function as the input to the current call. We could repeat up to n times:

x2, y2 = f(x1, y1, a, b)
x3, y3 = f(x2, y2, a, b)
x4, y4 = f(x3, y3, a, b)
...
xn-1, yn-1 = f(xn-2, yn-2, a, b)
xn, yn = f(xn-1, yn-1, a, b)

For large enough values of n, the resulting point at xn, yn will fall into one of two categories:

1- The point will still be close to the origin (0,0) of the plane. We define close to mean a distance less than or equal to 2.

2- The point will be far from the origin. We define far to mean a distance greater than 2.

If the point is close to the origin, it is part of the Mandelbrot set for f(x,y,a,b). Otherwise it is not part of the Mandelbrot set. A point that is not part of the Mandelbrot set “escapes” at the first iteration where the new (x,y) point is a distance of more than 2 from the origin. For points that escape, we will want to remember the “escape count”, or which iteration it escaped.

From Functions to Images

So, where do the interesting pictures come from?

We choose an actual function for f(x,y,a,b), then color each point in the plane based on how far it is from being in the Mandelbrot set for the selected function. “How far” is the “escape count”.

Actually, there are infinitely many points in the plane, so we can’t do every point. Instead, we select a regular grid of points each representing the points near it in the plane. For each point in the grid:

Now, we have a set of integers (the escape values) that represent how close each of the points in the grid are to the Mandelbrot set for f(x,y,a,b). Larger numbers mean they are closer to the Mandelbrot set.

Since the points selected are in a regular grid, we can pair each grid point with a pixel in a rectangular image. We assign the color of pixel based on the escape value of the corresponding grid point. All pixels associated with the same escape value will have the same color.

Defining a Regular Grid

See the description in the Julia set assignment.

Our Function f(x,y,a,b)

For our function f(x,y,a,b) we will use this definition:

x' = x*x - y*y + a
y' = 2*x*y + b

where, a and b are the coordinates of the original point in the plane. Note this is similar to, but different from the Julia set, where a and b where fixed values for an entire image calculation. Here, they depend on the point whose escape count you are calculating.

Assignment

In this assignment you will create a class to calculate and store a Mandelbrot set’s escape values. Most of the work has already been done in the NumberGrid and ComplexFractal classes. In this assignment, you will create a new class MandelbrotSet class, inheriting from ComplexFractal and adding a few methods specific to the calculation of Mandelbrot sets.

You will also extend the ppm_menu program to add a few new commands.

The new commands required are:

Programming Requirements

The following files must be updated or created and stored in the src directory of your repository.

Create MandelbrotSet.{h,cpp}

These files will be used to declare and define the MandelbrotSet class.

No data members are required. Note that the NumberGrid’s maximum number will be used for the MandelbrotSet’s maximum escape count. Also note that MandelbrotSet inherits from ComplexFractal.

Methods:

Update/Add Functions in image_menu.h and controllers.cpp

Add or update the following function declarations to the header file and implementations to the .cpp file.

Table of New Commands

Command Name Function Name Description
mandelbrot setMandelbrotFractal Choose to make a Mandelbrot set.

Update Makefile

The following commands should work correctly.

Additional Documentation

Sample PPM Images

Show Off Your Work

To receive credit for this assignment, you must

Additionally, the program must build, run and give correct output.

Extra Challenges (Not Required)

Last Updated 09/11/2023