Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import sys, cmath
- SIDE = 2048
- MAXITER = 1024
- im = Image.new('RGBA',(SIDE,SIDE),(255,255,255,255))
- #-----------------------------------------------------------------------
- # mandelbrot.py
- #-----------------------------------------------------------------------
- def mandel(z0, limit):
- z = z0
- ret=limit
- for t in range(limit):
- if abs(z) > 2:
- ret=t
- break
- z = z * z + z0
- return (ret, z)
- #-----------------------------------------------------------------------
- n=SIDE
- xc = 0
- yc = 0
- size = 4.2
- for col in range(SIDE):
- for row in range(SIDE):
- x0 = xc - (size / 2) + (size * col / SIDE)
- y0 = yc - (size / 2) + (size * row / SIDE)
- z0 = complex(x0, y0)
- (iteration,zn) = mandel(z0, MAXITER)
- if iteration < MAXITER:
- im.putpixel((col,row),(255*(iteration%2),255*(iteration%2),255*(iteration%2)))
- else:
- diff = zn-z0
- angle = cmath.phase(diff)
- im.putpixel((col,row),(0,0,int(angle*512/cmath.pi)%255))
- im.save('
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement