import PIL from PIL import ImageDraw from PIL import Image from PIL import ImageColor #float left, float right , float bottom, float top-what we are looking at in C #view=(-0.49375, -0.46875, 0.04146, 0.059375)#good for cubie thing with detail 25 #view=(-0.5, 2.0, -1.5, 1.5) #good for mandlebrot #view=(-1.0, 1.0, -1.0, 1.0)#standard view=(-2.0, 2.0, -2.0, 2.0) # (int width, int height) imDim=(400,400) imCen=(int(float(imDim[0])/2.0),int(float(imDim[1])/2.0)) #(double precision) how fine we are dividing up the window. we divided it up into precision parts on each dimension #320.0#it looks like it is best when it is a little bigger than the dimensions #seriously like +1 does the job precision=401.0 #the image stuff imFile=Image.new("RGB",imDim) imCanvas=ImageDraw.Draw(imFile) colors=[ "#00ff00", #0 1 2 3 4 5 6 7 8 9 a b c d e f "#00ff19", #0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 "#00ff32", "#00ff4b", "#00ff64", "#00ff7d", "#00ff96", "#00ffaf", "#00ffc8", "#00ffe1", "#19ffff", ] #imColor=ImageColor.getcolor("lightBlue","RGBA") #alg(complex c)make sure you start with x being c def alg1(x,c): #x=c if x==None: return x else: try: x=x**2-c except OverflowError: x=None return x def alg2(x,c): #x=c if x==None: return x else: try: x=(1.0-2.0j)*x**2+0.5j-c except OverflowError: x=None return x def alg3(x,c): if x==None: return x else: try: x=x**2+-c except OverflowError: x=None return x #comesh(float precision) def comesh(d=precision):#the coefficient mesh f=list() width=float(view[1]-view[0]) for i in range(int(d)): f.append((float(i)*width/float(d))+view[0]) return f def comeshx(d=precision): f=list() width=float(view[1]-view[0]) for i in range(int(d)): f.append((float(i)*width/float(d))+view[0]) return f def comeshy(d=precision): f=list() width=float(view[3]-view[2]) for i in range(int(d)): f.append((float(i)*width/float(d))+view[2]) return f #cx(int x, int w) def cx(x,w=imDim[0]): return float(x) #cy(int y, int h) def cy(y,h=imDim[1]): return (float(h)-float(y)-1.0) def ccx(x): return int(imCen[0]+cx(x)) def ccy(y): return int(imCen[1]+cy(y)) def dx(x): m=float(imDim[0])/(view[1]-view[0]) t=(float(x)-view[0])*m return cx(t) def dy(y): m=float(imDim[1])/(view[3]-view[2]) t=(float(y)-view[2])*m return cy(t) def dc(c): return (dx(c.real),dy(c.imag)) """ def mkLayer1(meshx,meshy,layer,): for i in meshx: for k in meshy: c=complex(i,k) x=c x=alg1(x,c) if ((x is not None) and abs(x)<10): imCanvas.point(dc(c),colors[p]) else: pass """ def mkPic1(): meshx=comeshx() meshy=comeshy() for i in meshx: for k in meshy: c=complex(i,k) x=c xcolor="black" for p in range(2): x=alg1(x,c) for p in range(11): x=alg1(x,c) if ((x is not None) and abs(x)<10): xcolor=colors[p] else: break imCanvas.point(dc(c),xcolor) imFile.save("mkPic8.gif") def mkPic2(detail): meshx=comeshx() meshy=comeshy() for i in meshx: for k in meshy: c=complex(i,k) x=c xcolor="black" for p in range(detail): x=alg2(x,c) for p in range(11): x=alg2(x,c) if ((x is not None) and abs(x)<10): xcolor=colors[p] else: break imCanvas.point(dc(c),xcolor) imFile.save("pics/mkPic12.gif") def mkPic3(c,depth): meshx=comeshx() meshy=comeshy() for i in meshx: for k in meshy: x=complex(i,k) xcolor="black" for p in range(depth): x=alg3(x,c) for p in range(11): x=alg3(x,c) if ((x is not None) and abs(x)<10): xcolor=colors[p] #print x , abs(x) else: break imCanvas.point(dc(complex(i,k)),xcolor) imFile.save("pics/julia/mkjulia2.gif") mkPic3(complex(-0.4,0.4),6)