Advertisement
Guest User

mandelbrotset

a guest
Apr 19th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from PIL import Image
  2. import sys, cmath
  3.  
  4. SIDE = 2048
  5. MAXITER = 1024
  6. im = Image.new('RGBA',(SIDE,SIDE),(255,255,255,255))
  7.  
  8. #-----------------------------------------------------------------------
  9. # mandelbrot.py
  10. #-----------------------------------------------------------------------
  11.  
  12. def mandel(z0, limit):
  13.     z = z0
  14.     ret=limit
  15.     for t in range(limit):
  16.         if abs(z) > 2:
  17.             ret=t
  18.             break
  19.         z = z * z + z0
  20.        
  21.     return (ret, z)
  22.  
  23. #-----------------------------------------------------------------------
  24.  
  25. n=SIDE
  26. xc = 0
  27. yc = 0
  28. size = 4.2
  29.  
  30. for col in range(SIDE):
  31.     for row in range(SIDE):
  32.         x0 = xc - (size / 2) + (size * col / SIDE)
  33.         y0 = yc - (size / 2) + (size * row / SIDE)
  34.         z0 = complex(x0, y0)
  35.         (iteration,zn) = mandel(z0, MAXITER)
  36.         if iteration < MAXITER:
  37.            im.putpixel((col,row),(255*(iteration%2),255*(iteration%2),255*(iteration%2)))
  38.         else:
  39.            diff = zn-z0
  40.            angle = cmath.phase(diff)
  41.            im.putpixel((col,row),(0,0,int(angle*512/cmath.pi)%255))        
  42.  
  43. im.save('
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement