Guest User

Untitled

a guest
Oct 12th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import matplotlib
  2.  
  3. matplotlib.use('Agg')
  4.  
  5. from mpi4py import MPI
  6. import numpy as np
  7. import pylab
  8.  
  9. INITIAL_Z = 0.4
  10. comm = MPI.COMM_WORLD
  11. size = comm.Get_size()
  12. rank = comm.Get_rank()
  13.  
  14. min_x = float(input("Enter min_x:\n"))
  15. min_y = float(input("Enter max_x:\n"))
  16. max_x = float(input("Enter min_y:\n"))
  17. max_y = float(input("Enter max_y:\n"))
  18. x = int(input("Enter x (width):\n"))
  19. y = int(input("Enter y (height):\n"))
  20. iters = int(input("Enter number of iterations (0, 255):\n"))
  21. print('Please wait...')
  22.  
  23.  
  24. def iterations(real, imag, iters):
  25. z = INITIAL_Z
  26. r = complex(real, imag)
  27. for i in range(iters):
  28. z = z * r * (1 - z)
  29. if z.real * z.real + z.imag * z.imag > 3:
  30. return 255 * i // iters
  31. return 255
  32.  
  33.  
  34. def create_fractal(min_x, max_x, min_y, max_y, image, iters):
  35. height = image.shape[0]
  36. width = image.shape[1]
  37. pixel_size_x = (max_x - min_x) / width
  38. pixel_size_y = (max_y - min_y) / height
  39. for x in range(width):
  40. real = min_x + x * pixel_size_x
  41. for y in range(height):
  42. imag = min_y + y * pixel_size_y
  43. color = iterations(real, imag, iters)
  44. image[y, x] = color
  45. return image
  46.  
  47.  
  48. image = np.zeros((y, x))
  49. create_fractal(min_x, min_y, max_x, max_y, image, iters)
  50. pylab.imshow(image, aspect='auto', extent=[max_x, max_y, min_y, min_x])
  51. pylab.gca().invert_yaxis()
  52. pylab.gray()
  53. pylab.savefig('result.png')
  54. print('Done.')
Add Comment
Please, Sign In to add comment