Amir Parvardi
Amir Parvardi

Reputation: 141

Combining nine-fold cusp multibrot and enneagram using Python

I am working on Python and LaTeX (preferably vector graphics TikZ/Asymptote/PGF/Metapost/GeoGebra, in that order) codes that generates this animation by running simple code on your terminal.

Here is a thread on Tex.SE in which several methods of drawing the Mandelbrot set are discussed but I was not able to modify the mathematical equations in LaTeX as easy as in Python. Therefore I switched to Python and produced high resolution outputs as close to vector graphics as possible (~2,000 dpi). I would like to draw multibrots as generally defined as possible. For instance, when d is negative.

Enneabrot

Enneabrot-animation

The following code was taken from this Mandelbrot (dimension=2) project on GitHub and I needed to create the higher dimensional versions of this fractal project such as the Triabrot (dimension=4), Pentabrot (dimension=6), Heptabrot (dimension=8), and Enneabrot (dimension=10) by changing the exponent in the recursive equation that defines the Mandelbrot set. In other words, instead of z_{n+1} = z_n * z_n + z_0 for the Mandelbrot fractal, we define a variable d for dimension and then the equation for the d-dimensional Multibrot would be z_{n+1} = z_n^d + z_0 and each such equation will produce d-1 cusps in the figure of its stability zone. To learn more on this subject, watch these two YouTube videos: Times Tables by Mathologer and Mandelbrot Set by Numberphile.

It is necessary to change the axis for every patch of outputs; this happens because the fractals move in the complex plane and we need to move along our lens to watch them through Python. What other formulas could we use? Maybe axisFix = ((d^2-4)/d)/10? In this proposed formula, d^2-4 is there because I want the Mandelbrot fractal (d=2) to be printed right at the centre were it is printed without any displacement. So, the value of the axis translation would be zero. This is funny because it is also zero for d=-2 which means that we must also be trying to look at equations like z_{n+1}=z_n^{-2.0} + z_0. The goal is to find the smoothest function f(d) such that f(2)=0 and make an animation by increasing the value of d by increments of small size (0.01-0.1) and printing the output of the mandelbrot(threshold, density, dimension) function defined here as an animation. The smoother the function, the smoother the transition of slides in the animation of slides in the presentation.

import numpy as np
import matplotlib.pyplot as plt
# counts the number of iterations until the function diverges or
# returns the iteration threshold that we check until
def countIterationsUntilDivergent(c, threshold, d):
    z = complex(0, 0)
    for iteration in range(threshold):
# here is the recurrence relation z_{n+1} = z_n^d + z_0, used for 
# drawing d-1-dimensional Mandelbrot creatures (growing fractals)
        z = z**d + c
        if abs(z) > 4:
            break
            pass
        pass
    return iteration

# takes the iteration limit before declaring function as convergent and
# takes the density of the atlas
# create atlas, plot mandelbrot set, display set
def mandelbrot(threshold, density, d):
# it is necessary to change the axis for every patch of outputs;
# this happens because the fractals move in the complex plane
# and we need to move along our lens to watch them through Python
## what other formulas could we use? Maybe axisFix = ((d^2-4)/d)/10?
## d^2-4 is there because I want the Mandelbrot fractal (d=2)
## to be right there were it is printed without any replacement
## so the value of the axis translation would be zero. This is
## funny because it is also zero for d=-2 which means that
## we must also be trying to look at equations like
### z_{n+1}=z_n^{-2.0} + z_0
### the goal is to find the smoothest function
### f(d) such that f(2)=0 and make an animation 
### by increasing the value of d by increments of small size (0.01-0.1)
### and printing the output of the mandelbrot function defined here
### as an animation. The smoother the function, the smoother
### the transition of slides in the animation
    axisFix = d/10 
    # location and size of the atlas rectangle
    realAxis = np.linspace(-2.25+axisFix, 0.75+axisFix, density)
    imaginaryAxis = np.linspace(-1.5, 1.5, density)
    # realAxis = np.linspace(-0.22, -0.219, 1000)
    # imaginaryAxis = np.linspace(-0.70, -0.699, 1000)
    realAxisLen = len(realAxis)
    imaginaryAxisLen = len(imaginaryAxis)

    # 2-D array to represent mandelbrot atlas
    atlas = np.empty((realAxisLen, imaginaryAxisLen))

    # color each point in the atlas depending on the iteration count
    for ix in range(realAxisLen):
        for iy in range(imaginaryAxisLen):
            cx = realAxis[ix]
            cy = imaginaryAxis[iy]
            c = complex(cx, cy)
            atlas[ix, iy] = countIterationsUntilDivergent(c, threshold, d)
            pass
        pass

    # plot and display mandelbrot set
    fig1 = plt.gcf()
    plt.axis('off')
    # plt.savefig('mandel.eps', format='eps')
    plt.imshow(atlas.T, interpolation="nearest")
    # plt.show()
    output_name = str(d)+'.pdf'
    fig1.savefig(output_name, format='pdf', bbox_inches='tight', dpi=2000)

# time to party!!
dimensions = np.arange(10, 100) / 10
# for d in dimensions:
#     mandelbrot(120, 1000, d)

# Enneabrot
mandelbrot(120, 1000, 10)
# Heptabrot
mandelbrot(120, 1000, 8)
# Pentabrot
mandelbrot(120, 1000, 6)
# Triabrot
mandelbrot(120, 1000, 4)
# Mandelbrot
mandelbrot(120, 1000, 2)

Upvotes: 2

Views: 260

Answers (1)

Amir Parvardi
Amir Parvardi

Reputation: 141

Here are the results, thanks to Aryan Hemmati for editing the final photo by merging the Enneagram of the soul with the ten-dimensional Mandelbrot fractal.

Enneabrot animation

I need a Python and LaTeX (preferably vector graphics TikZ/Asymptote/PGF/Metapost/GeoGebra, in that order) that generates this animation by running simple code on your terminal. We could easily change the parameters to make a Heptabrot (d=8), Pentabrot (d=6), or even a Triabrot (d=4). I am attaching the code for drawing the Enneabrot (d=10) using Python and I have modified this code by Danyaal Rangwala and defined a new variable d (dimension) in the recursive equation calculating the precise zone of equilibrium for the solution, and this eventually reveals Enneabrot as the last number I tried for generating this kind of fractals (started from d=1.0 with 0.1 incrementations up to d=10.0).

Here I will post the outputs for the Mandelbrot fractal (d=2) as well as the fractals I defined above: Enneabrot (d=10), Heptabrot (d=8), Pentabrot (d=6), or even a Triabrot (d=4). Other diagrams to follow in the next editions of this answer.

Mandelbrot (d=2) Mandelbrot


Triabrot (d=4) Triabrot


Pentabrot (d=6) Pentabrot


Heptabrot (d=8) Heptabrot


Enneabrot (d=10) Enneabrot

Upvotes: 2

Related Questions