calcpage

mandel_serial01.py

Jan 29th, 2020
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. #mandel_serial01.py
  2. #Works in SAGE without command arguments
  3. def mandelbrot(x, y, maxit):
  4.     c = x + y*1j
  5.     z = 0 + 0j
  6.     it = 0
  7.     while abs(z) < 2 and it < maxit:
  8.         z = z**2 + c
  9.         it += 1
  10.     return it
  11.  
  12. x1, x2 = -2.0, 1.0
  13. y1, y2 = -1.0, 1.0
  14. w, h = 150, 100
  15. maxit = 128
  16.  
  17. ans=""
  18. import numpy
  19. C = numpy.zeros([h, w], dtype='i')
  20. dx = (x2 - x1) / w
  21. dy = (y2 - y1) / h
  22. for i in range(h):
  23.     y = y1 + i * dy
  24.     ans+="\n"
  25.     for j in range(w):
  26.         x = x1 + j * dx
  27.         num = mandelbrot(x, y, maxit)
  28.         C[i, j] = num
  29.         ans+=str(num)
  30.  
  31. print(ans)  
  32.      
  33. from matplotlib import pyplot
  34. pyplot.imshow(C, aspect='equal')
  35. #pyplot.spectral()
  36. pyplot.show()
Add Comment
Please, Sign In to add comment