farry

mandelbrot-bifurcation.py

Apr 19th, 2020
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import numpy as np
  4. from PIL import Image, ImageColor # pillow fork of PIL
  5.  
  6. height, width = 599, 750
  7. grid = np.ogrid[-1.0:1.0:1j*height, -2.0:.5:1j*width]
  8. c = grid[1] + 1j * grid[0]
  9. z = c.copy()
  10.  
  11. logisticmap = np.zeros((height, width), dtype=np.uint8)
  12. x = np.arange(width, dtype=np.int64)
  13.  
  14. for iterate in range(500):
  15.     mandelbrot = abs(z) < 50.0
  16.     np.putmask(z, mandelbrot, z*z + c)
  17.    
  18.     realaxis = z[height // 2 ].real
  19.     y = np.int16( 0.15 * (4.5 - realaxis) * (height - 1))
  20.     np.clip(y, 0, height - 1, y)
  21.     if iterate > 100:
  22.         logisticmap[y,x]  = 1
  23.  
  24. colors = ("white","black","red", "black")
  25. rgbcolors = np.uint8(list(map(ImageColor.getrgb, colors)))
  26. rgb = rgbcolors[logisticmap + 2 * mandelbrot]
  27. image = Image.fromarray(rgb, mode="RGB")
  28. image.save('mandelbrot-bifurcation.png')
  29. image.show()
Advertisement
Add Comment
Please, Sign In to add comment