# mandelbrot2.py # NextMove Software # April 2010 def main(): d0 = 0.0004 xo = -0.7434 yo = 0.1058 print 'P3\n512 512\n256\n'; delta = d0/512.0 y = yo range512 = range(512) for yp in range512: x = xo for xp in range512: # Mandelbrot calculation count = 1 a = x b = y while 1: apb = a+b amb = a*b dab = 2.0*amb size = apb*apb-dab if size >= 4.0: break count += 1 if count == 256: count = 0 break a = apb*(a-b)+x; b = dab+y; # Convert count to r,g,b if count < 32: r = 0 g = 0 b = 4*count elif count < 64: t = count - 32 r = 0 g = 6*t b = 128-4*t elif count < 96: t = count - 64 r = 8*t g = 255 b = 2*t elif count < 128: t = count - 96 r = 255 g = 255-6*t b = 64-2*t elif count < 160: t = count - 128 r = 255-6*t g = 64-2*t b = 0 elif count < 192: t = count - 160 r = 54+6*t g = 0; b = 8*t; elif count < 224: t = 8*(count - 192) r = 255 - t g = t b = 255 else: r = 8*(count-224) g = 255 b = 255 print r , g , b x += delta y -= delta main()