#code snippets for lab9_julia-faces.py #refer to lab9 for details ################## replaces the entire "if(iter==MAXITS):" block bins[i,j]=iter ################## insert after MAXITS assignment L=MAXITS**(1./3.) LL=L*L LLL=LL*L #this is MAXITS ################## replaces colorcode=color.black colorcode=( int(B/LL)/(L), int((B/L)%L)/(L), int(B%L)/(L) ) ################## define julia def julia(a,c,MAX,bins): number=bins.shape[0]-1 ####calculate the julia map ################## define draw_region def draw_region(c,MAX,bins): number=bins.shape[0]-1 ####draw the region ################## place near the top, to create c and bins c=complex(0.,0.) bins=zeros(((number+1),(number+1))) ################## use our newly created functions bins=julia(a,c,MAX,bins) draw_region(c,MAX,bins) ################## zoom functions ################## ## ## zoom_mode=1 #for point-zooming (zoom_mode=1) zoom=2.0 zoom_scale_step=math.pow(zoom,1./20.) #scaling factor used for point-zooming in #for region-zooming (zoom_mode=0) selected=0 band=curve(pos=5*[vector(0,0,0)] , visible=0) while 1: if zoom_mode: ####################### # #Now... WHEN A POINT IS CLICKED, #TRANSLATE THE scene.center TO THE CLICKED POINT, WHILE ZOOMING if scene.mouse.events: MOUSE_EVENT=scene.mouse.getevent() #print MOUSE_EVENT.press, MOUSE_EVENT.pos if (MOUSE_EVENT.press=='left' or MOUSE_EVENT.press=='right' or MOUSE_EVENT.press=='middle'): if MOUSE_EVENT.press=='left': #ZOOM IN scale_factor=zoom scale_step=zoom_scale_step elif MOUSE_EVENT.press=='right': #ZOOM OUT scale_factor=1./zoom scale_step=1./zoom_scale_step else: #NO ZOOM scale_factor=1.0 scale_step=1.0 target=MOUSE_EVENT.pos c=complex(target[0], target[1]) scene.title="a=(%10.7f,%10.7f) c=(%10.7f,%10.7f) MAX=%10.7f" % (a.real,a.imag, c.real,c.imag,MAX) print scene.title MAX /= scale_factor if scale_factor>=1: bins=julia(a,c,MAX,bins) draw_region(c,MAX,bins) step=(target-scene.center)/20. for i in arange(0,20): rate(50) scene.center +=step scene.scale *= scale_step #(zoom_scale_step**20.=2.0) scene.center=target # ####################### else: ####################### # #Now... WHEN A POINT IS CLICKED, DRAGGING THE MOUSE SELECTS A REGION #CENTERED AT THE CLICKED POINT. #TRANSLATE THE scene.center TO THE CLICKED POINT, WHILE ZOOMING if selected==0 and (scene.mouse.clicked or scene.mouse.events): if scene.mouse.clicked: scene.mouse.getclick() else: scene.mouse.getevent() selected=1 C1=scene.mouse.pos band.pos=5*[C1] band.visible=1 if selected==1: C2=scene.mouse.pos UL=C1-1*(C2-C1) #upper-left corner band.pos[0]=band.pos[4]=UL band.pos[1][0]=UL[0] band.pos[1][1]=C2[1] band.pos[2]=C2 band.pos[3][0]=C2[0] band.pos[3][1]=UL[1] if scene.mouse.events: m1=scene.mouse.getevent() if m1.drop or m1.click: selected=0 diff=C2-C1 if mag(diff)>0: MAXNEW=min(abs(diff[0]),abs(diff[1])) scale_factor=MAX/MAXNEW scale_step=math.pow(scale_factor,1./20.) #scaling factor used for zooming in MAX=MAXNEW else: scale_factor=1 scale_step=1 c=complex(C1[0], C1[1]) target=C1 scene.title="a=(%10.7f,%10.7f) c=(%10.7f,%10.7f) MAX=%10.7f" % (a.real,a.imag, c.real,c.imag,MAX) print scene.title if scale_factor>=1: bins=julia(a,c,MAX,bins) draw_region(c,MAX,bins) step=(target-scene.center)/20. for i in arange(0,20): rate(50) scene.center +=step scene.scale *= scale_step #(zoom_scale_step**20.=2.0) scene.center=target # ####################### ## ## ################## ##################