Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. def mandelbrot( h,w, maxit=20 ):
  5. """Returns an image of the Mandelbrot fractal of size (h,w)."""
  6. y,x = np.ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ]
  7. c = x+y*1j
  8. z = c
  9. divtime = maxit + np.zeros(z.shape, dtype=int)
  10.  
  11. for i in range(maxit):
  12. z = z**2 + c
  13. diverge = z*np.conj(z) > 2**2 # who is diverging
  14. div_now = diverge & (divtime==maxit) # who is diverging now
  15. divtime[div_now] = i # note when
  16. z[diverge] = 2 # avoid diverging too much
  17.  
  18. return divtime
  19. plt.imshow(mandelbrot(800,800))
  20. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement