RESEARCH NOTEBOOK
Animation of Mandelbrot Fractals
import matplotlib.pyplot as plt import numpy as np import math import matplotlib.animation as animation from random import randint
np.warnings.filterwarnings(“ignore”)
def complex_matrix(xmin, xmax, ymin, ymax, pixel_density): re = np.linspace(xmin, xmax, int((xmax - xmin) * pixel_density)) im = np.linspace(ymin, ymax, int((ymax - ymin) * pixel_density)) return re[np.newaxis, :] + im[:, np.newaxis] * 1j
c = complex_matrix(-2, 2, -1.5, 1.5, pixel_density=512)
fig, ax = plt.subplots()
def is_stable(c, e, num_iterations, z = 0): for _ in range(num_iterations): z = z ** e + c return abs(z) <= 2
e = 2 def vis(i) : e=2+i*0.1 if i%10 == 0 : print(e) visualize(e, 0, 20)
def visualize(exponent=2, z=0, iter=20) : ax.clear() ax.imshow(is_stable(c, exponent, iter, z), cmap=‘plasma’ )
ani = animation.FuncAnimation(fig, vis, frames=150, interval=10, save_count= 50 , repeat=False) ani.save(‘animation.gif’, fps=5) #ani .save(‘growingCoil.mp4’, writer = ‘ffmpeg’, fps = 5)