farry

mandelbrot-cosine-numpy.py

Sep 3rd, 2019
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import numpy as np
  3. from PIL import Image # Pillow fork of PIL
  4.  
  5. w, h = 1200, 960
  6. xc, yc, scale = - 0.35, 0.005, 1.1
  7. imax, zmax = 100, 100
  8.  
  9. x,y=np.ogrid[xc - scale: xc + scale: 1j * w,
  10.     (yc - scale) * h/w: (yc + scale) * h/w: 1j * h]
  11. c = x + 1j*y
  12. ones = np.ones_like(x*y)
  13. its = np.zeros_like(ones)
  14. z = c * 0
  15. np.warnings.filterwarnings('ignore', '(overflow|invalid)')
  16.  
  17. for n in range(imax):
  18.     mask = abs(z.real) < zmax
  19.     m = np.where(mask)
  20.     its[m] = n
  21.     z[m] = np.pi * np.cos(z[m])  + c[m]
  22.  
  23. backgnd = np.log(its - np.log(np.log(abs(z.imag))) / 3) / 3
  24. np.putmask(backgnd, mask, 0*ones)
  25. tones = np.array(3*[backgnd]).T
  26. val = np.maximum(0.0, 1.0 - abs(1.0 - backgnd))
  27. blues = np.array((val**4, val**2.5, val)).T
  28. sepias = np.array((val, val**1.5, val**3)).T
  29. color = np.where(tones<1.0, blues, sepias)
  30. rgb = np.uint8(np.minimum(1.0, color) * 255)
  31. img = Image.fromarray(rgb, mode="RGB")
  32. img.save("mand.png")
  33. img.show()
Advertisement
Add Comment
Please, Sign In to add comment