Advertisement
Guest User

Untitled

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