from visual.graph import * scene = display(title='Mandelbrot Set', x=0, y=0, width=800, height=800, center=(0,0,0), background=(0,0,0)) Xaxis=curve( pos=[(-2,0),(1,0)] ) Yaxis=curve( pos=[(0,-1.5),(0,1.5)] ) XMIN = -2 XMAX = 2 YMIN = 0 YMAX = 2 r=0.005 dot=sphere(pos=(0,0,0), radius=0.02, color=color.cyan) autoscale=true max_iteration = 20 for Ci in arange(YMIN, YMAX, r): # range over all pixel positions for Cr in arange(XMIN, XMAX, r): Xnew=0 Ynew=0 Xold=0 Yold=0 iteration = 0 while ( Xnew*Xnew + Ynew*Ynew < 4 and iteration < max_iteration): Xnew = Xold*Xold-Yold*Yold + Cr Ynew = 2*Xold*Yold +Ci iteration = iteration + 1 Xold=Xnew Yold=Ynew if(Xnew*Xnew + Ynew*Ynew < 4): sphere(pos=(Cr, Ci,0), radius=0.01) sphere(pos=(Cr,-Ci,0), radius=0.01) while True: if scene.mouse.clicked: m = scene.mouse.getclick() loc = m.pos print loc dot.pos=m.pos Xnew=0 Ynew=0 Xold=0 Yold=0 iteration = 0 autoscale = False userzoom = False userspin = False while ( Xnew*Xnew + Ynew*Ynew < 4 and iteration < 40): Xnew = Xold*Xold-Yold*Yold + m.pos.x Ynew = 2*Xold*Yold +m.pos.y iteration = iteration + 1 Xold=Xnew Yold=Ynew rate(2) dot.pos=(Xnew,Ynew,0) print iteration,dot.pos.x,dot.pos.y