def mandelbrot(c, maxIter): iter = 0 z = c while iter < maxIter: z = z*z + c if abs(z) > 2: return iter iter = iter + 1 return -1 import Image width = 1000 height = 1000 img = Image.new('RGB',(width,height)) colormap = [] for i in range(0,64): colormap.append((i*4,i*4,0)) for i in range(0,64): colormap.append((i*4,0,0)) for i in range(0,64): colormap.append((0,i*4,0)) for i in range(0,64): colormap.append((0,0,i*4)) center = (-0.75, 0.25) size = 0.125 for i in range(0,width): x = (i/(width-1.0)*size) - size/2.0 + center[0] for j in range(0,height): y = (j/(height-1.0)*size) - size/2.0 + center[1] m = mandelbrot(x+y*1j, 64) if m == -1: img.putpixel((i,j),(0,0,0)) else: img.putpixel((i,j),colormap[(64-m)*4]) img.save('mandelbrot.tif')