import numpy as np
import matplotlib.pyplot as plt

def mandelbrot(h,w, maxit=20):
    x,y = np.meshgrid(np.linspace(-2, 0.8, w), np.linspace(-1.4, 1.4, h))
    c = x + y*1j
    z = c
    exceeds = np.zeros(z.shape, dtype=bool)
    for iteration in range(maxit):
        z = z**2 + c
        exceeded = abs(z) > 4
        exceeds_now = exceeded & (np.logical_not(exceeds))
        exceeds[exceeds_now] = True
        z[exceeded] = 2 # limit the values to avoid overflow
    return exceeds

plt.imshow(mandelbrot(600,600),cmap='gray')
plt.savefig('ex204.png', dpi=72)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading