DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Julia Set

Introduction

The Julia set is a mathematical set defined from a function. In addition to its merits in complex dynamics, it can be used to generate interesting images. Every point in a 2 dimensional plane can be categorized as inside or outside of the Julia set for a particular function choice.

Finding Points in the Julia Set

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

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

x1, y1 = f(x0, y0)

Repeat that process (iterate) 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)
x3, y3 = f(x2, y2)
x4, y4 = f(x3, y3)
...
xn-1, yn-1 = f(xn-2, yn-2)
xn, yn = f(xn-1, yn-1)

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 resulting point is close to the origin, it is part of the Julia set for the function f(x,y). Otherwise it is not part of the Julia set for the function f(x,y). A point that is not part of the Julia 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 on 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), then color each point in the plane based on how far it is from being in the Julia 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 Julia set for f(x,y). Larger numbers mean they are closer to the Julia 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

We will use the ComplexFractal class to calculate (x,y) values from (row,column) numbers.

Our Function f(x,y)

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

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

where, a and b are parameters used to configure a particular version of the family of functions described by these equations.

Assignment

In this assignment you will create a class to create and store a Julia set’s escape values. It will inherit from ComplexFractal, which inherits from the NumberGrid class. We will use the NumberGrid height and width to store the grid size. The NumberGrid maximum number will be used as the maximum escape value, and the NumberGrid numbers will be the JuliaSet escape values. The ComplexFractal class will keep track of mapping between row,column and x,y coordinates. The JuliaSet class will add the ability to calculate escape counts for points in the plane. It will also track the a and b parameters necessary for our chosen function.

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

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 JuliaSet.{h,cpp}

This class inherits publicly from ComplexFractal.

The NumberGrid’s maximum number will be used for the JuliaSet’s maximum escape count.

Data Members:

Methods:

Add New Functions to image_menu.h and image_drawing.cpp

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

Table of New Commands

Command Name Function Name Description
julia-parameters setJuliaParameters Set the parameters of the Julia Set function.
complex-fractal setComplexFractal Choose to make a complex plane.
julia setJuliaFractal Choose to make a Julia 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