SHARE
TWEET

CIS_mandelSeq.py

calcpage Feb 16th, 2013 1,715 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. def mandelbrot(x, y, maxit):
  3.     c = x + y*1j
  4.     z = 0 + 0j
  5.     it = 0
  6.     while abs(z) < 2 and it < maxit:
  7.         z = z**2 + c
  8.         it += 1
  9.     return it
  10.  
  11. x1, x2 = -2.0, 1.0
  12. y1, y2 = -1.0, 1.0
  13. w, h = 150, 100
  14. maxit = 127
  15.  
  16. import numpy
  17. C = numpy.zeros([h, w], dtype='i')
  18. dx = (x2 - x1) / w
  19. dy = (y2 - y1) / h
  20. for i in range(h):
  21.     y = y1 + i * dy
  22.     for j in range(w):
  23.         x = x1 + j * dx
  24.         C[i, j] = mandelbrot(x, y, maxit)
  25.  
  26. from matplotlib import pyplot
  27. pyplot.imshow(C, aspect='equal')
  28. pyplot.spectral()
  29. pyplot.show()
RAW Paste Data
Top