guitar-player

fractal.py

May 29th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def mandel(n, m, itermax, xmin, xmax, ymin, ymax):
  2.     ix, iy = mgrid[0:n, 0:m]
  3.     x = linspace(xmin, xmax, n)[ix]
  4.     y = linspace(ymin, ymax, m)[iy]
  5.     c = x+complex(0,1)*y
  6.     del x, y
  7.     img = zeros(c.shape, dtype=int)
  8.     ix.shape = n*m
  9.     iy.shape = n*m
  10.     c.shape = n*m
  11.     z = copy(c)
  12.     for i in xrange(itermax):
  13.         if not len(z): break
  14.         multiply(z, z, z)
  15.         add(z, c, z)
  16.         rem = abs(z)>2.0
  17.         img[ix[rem], iy[rem]] = i+1
  18.         rem = -rem
  19.         z = z[rem]
  20.         ix, iy = ix[rem], iy[rem]
  21.         c = c[rem]
  22.     return img
Advertisement
Add Comment
Please, Sign In to add comment