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()
Like this:
Like Loading...
Related
Recent Comments