Advertisement
calcpage

mandel_serial00.py

May 14th, 2020
1,850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #runs on RPI, no commandline input, no *.png output
  3. #if chmod 755, then
  4. #./mandel_serial00.py
  5. import timeit
  6. def mandelbrot(x, y, maxit):
  7.     c = x + y*1j
  8.     z = 0 + 0j
  9.     it = 0
  10.     while abs(z) < 2 and it < maxit:
  11.         z = z**2 + c
  12.         it += 1
  13.     return it
  14.  
  15. x1, x2 = -2.0, 1.0
  16. y1, y2 = -1.0, 1.0
  17. w, h = 120, 100
  18. maxit = 256
  19.  
  20. start_time=timeit.default_timer()
  21. import numpy
  22. C = numpy.zeros([h, w], dtype='i')
  23. dx = (x2 - x1) / w
  24. dy = (y2 - y1) / h
  25. for i in range(h):
  26.     y = y1 + i * dy
  27.     for j in range(w):
  28.         x = x1 + j * dx
  29.         C[i, j] = mandelbrot(x, y, maxit)
  30. print("cpu time = " + str(timeit.default_timer()-start_time) + ' micro seconds')
  31.  
  32. #from matplotlib import pyplot
  33. #pyplot.imshow(C, aspect='equal')
  34. #pyplot.spectral()
  35. #pyplot.show()
  36.        
  37. import matplotlib.pyplot as plt
  38. plt.imshow(C, aspect='equal', cmap='nipy_spectral_r')
  39. #plt.brg()
  40. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement