#animates smooth transition from identity map to another self-map of complex plane #uses rims and spokes def rim(f,r,hue): th=var('th') return parametric_plot((f(r*exp(I*th)).real(), f(r*exp(I*th)).imag()),(th,0,2*pi),hue=hue) def spoke(f,th,rmin,rmax,hue): r=var('r') return parametric_plot((f(r*exp(I*th)).real(), f(r*exp(I*th)).imag()),(r,rmin,rmax),hue=hue) def middles(a,b,n): return [a+(i+.5)*(b-a)/float(n) for i in range(n)] def rims(f,a,b,n): radii=middles(a,b,n) hues=middles(0,1,n) return [rim(f,r,h) for (r,h) in zip(radii,hues)] def spokes(f,rmin,rmax,n): angles=middles(0,2*pi,n) hues=middles(0,1,n) return [spoke(f,th,rmin,rmax,h) for (th,h) in zip(angles,hues)] def homotopy(f,rmin,rmax,r_n,th_n,t_n): hom=[] for t in middles(0,1,t_n): g = lambda z: z*(1-t)+f(z)*t hom.append(sum(rims(g,rmin,rmax,r_n))+sum(spokes(g,rmin,rmax,th_n))) return hom rmin=1/3. rmax=3 r_n=6 th_n=20 t_n=50 f=lambda z: 1/z an=animate(homotopy(f,rmin,rmax,r_n,th_n,t_n)) show(an) #animates smooth transition from identity map to another self-map of complex plane #uses grid def horiz(f,y,xmin,xmax,hue): x=var('x') return parametric_plot((f(x+I*y).real(),f(x+I*y).imag()),(x,xmin,xmax),hue=hue) def vert(f,x,ymin,ymax,hue): y=var('y') return parametric_plot((f(x+I*y).real(),f(x+I*y).imag()),(y,ymin,ymax),hue=hue) def middles(a,b,n): return [a+(i+.5)*(b-a)/float(n) for i in range(n)] def horizs(f,a,b,c,d,n): ys=middles(c,d,n) hues=middles(0,1,n) return [horiz(f,y,a,b,h) for (y,h) in zip(ys,hues)] def verts(f,a,b,c,d,n): xs=middles(a,b,n) hues=middles(0,1,n) return [vert(f,x,c,d,h) for (x,h) in zip(xs,hues)] def homotopy_grid(f,xmin,xmax,ymin,ymax,x_n,y_n,t_n): hom=[] for t in middles(0,1,t_n): g = lambda z: z*(1-t)+f(z)*t hom.append(sum(horizs(g,xmin,xmax,ymin,ymax,x_n))+sum(verts(g,xmin,xmax,ymin,ymax,y_n))) return hom xmin=-2 xmax=2 ymin=-2 ymax=2 x_n=10 y_n=10 t_n=50 f=lambda z: 1/z an_g=animate(homotopy_grid(f,xmin,xmax,ymin,ymax,x_n,y_n,t_n)) show(an_g)