Advertisement
Guest User

Untitled

a guest
Jan 18th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import numpy
  2.  
  3. def mandel(n, m, itermax, xmin, xmax, ymin, ymax):
  4.     ix, iy = mgrid[0:n, 0:m]
  5.     x = linspace(xmin, xmax, n)[ix]
  6.     y = linspace(ymin, ymax, m)[iy]
  7.     c = x+complex(0,1)*y
  8.     del x, y
  9.     img = zeros(c.shape, dtype=int)
  10.     ix.shape = n*m
  11.     iy.shape = n*m
  12.     c.shape = n*m
  13.     z = copy(c)
  14.     for i in xrange(itermax):
  15.         if not len(z): break
  16.         multiply(z, z, z)
  17.         add(z, c, z)
  18.         rem = abs(z)>2.0
  19.         img[ix[rem], iy[rem]] = i+1
  20.         rem = -rem
  21.         z = z[rem]
  22.         ix, iy = ix[rem], iy[rem]
  23.         c = c[rem]
  24.     return img
  25.  
  26. if __name__=='__main__':
  27.     from pylab import *
  28.     import time
  29.     start = time.time()
  30.     I = mandel(800, 800, 100, -2, .5, -1.25, 1.25)
  31.     print 'Time taken:', time.time()-start
  32.     I[I==0] = 101
  33.     img = imshow(I.T, origin='lower left')
  34.     img.write_png('mandel.png', noscale=True)
  35.     show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement