Advertisement
calcpage

mandel_serial02.py

Feb 26th, 2020
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #mandel_serial02.py works with commandline arguments on RPI
  2. import sys
  3. print('len(sys.argv) = ' + str(len(sys.argv)))
  4. print('sys.argv[0] = ' + sys.argv[0])
  5. w, h, maxit = sys.argv[1], sys.argv[2], sys.argv[3]
  6. print('w = ' + w)
  7. print('h = ' + h)
  8. print('maxit = ' + maxit)
  9.  
  10. def mandelbrot(x, y, maxit):
  11.     c = x + y*1j
  12.     z = 0 + 0j
  13.     it = 0
  14.     while abs(z) < 2 and it < maxit:
  15.         z = z**2 + c
  16.         it += 1
  17.     return it
  18.    
  19. x1, x2 = -2.0, 1.0
  20. y1, y2 = -1.0, 1.0
  21. #w, h = 150, 100
  22. #maxit = 127
  23. w = int(w)
  24. h = int(h)
  25. maxit = int(maxit)
  26.  
  27. import numpy
  28. C = numpy.zeros([h, w], dtype='i')
  29. dx = (x2 - x1) / w
  30. dy = (y2 - y1) / h
  31. for i in range(h):
  32.     y = y1 + i * dy
  33.     for j in range(w):
  34.         x = x1 + j * dx
  35.         C[i, j] = mandelbrot(x, y, maxit)
  36.        
  37. import matplotlib
  38. matplotlib.use('Agg')
  39. import matplotlib.pyplot as plt
  40. #pyplot.imshow(C, aspect='equal')
  41. #pyplot.spectral()
  42. #pyplot.show()
  43. plt.imshow(C, cmap=plt.cm.twilight_shifted)
  44. plt.savefig("mandelbrot.png", dpi=200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement