Final Projects

June 13, 2017

The Pray Fractal

The Pray Fractal (and the Dragon Curve)

Andrew Pray

What is a fractal?

A fractal is a geometric shape that is created from various rules, that self replicates itself, or patterns of the grand design. Often very chaotic early levels come to form a much more defined image. As one zooms into a fractal, similar patterns emerge at a smaller scale.

Early Decisions:

Very quickly I discovered that in order to create any sort of fractal, you have to understand what mathematical equations go on behind the scenes. What formulas are constantly being repeated? What rules do I need to follow?

To learn what math I had to code I first turned to Desmos.

The functions on the left are what created the triangle on the right. The important part is that I can move the base angles to any x or y coordinate and a right triangle will still be drawn. The dragon fractal goes on to erase the base line, then repeat the pattern on the two legs. If you keep doing this, eliminating the base line and repeating the pattern, the dragon fractal is born!

One interesting problem:

There are a few ways a code can create a fractal. One uses array lists and creates new objects. I created a recursive function that calls itself inside the function.

This is the code I initially came up with. However, something very unexpected came from this code. This is the fractal, 14 levels deep.

This is the fractal’s coordinates: A:(5,520) and B:(-10,0)

It reminds me of the Sierpinski Triangle. I’ve never seen or heard of this fractal. So, we called it the Pray Fractal. This is the fractal at A:(5,10) and B:(-660,-5)Obviously, something has gone wrong. I went through each interval one by one and compared it to the dragon curve’s equivalent.

In my code, when x3 is less than x1, T becomes negative, making the following two lines place the coordinate inverted. Three lines of code fixed the problem:

if (x2>x3) {
x4=x3+d*(cos(T-HALF_PI));
y4=y3+d*(sin(T-HALF_PI));
}

Other features I added to my program were various key presses that allow the user to zoom in and out, mouse click to drag the image, and key presses that change the parameters.

Last thing:

I ended up saving multiple images of the fractal zooming in on itself in a data folder. This way the images could be placed on top of each other in a 3D modeling program. At that point, the fractal could be 3D printed.