def animate_contraction(g, e, frames = 12, **kwds):
- v1, v2 = e if not g.has_edge(v1,v2):
raise ValueError, "Given edge not found on Graph"
- gp = Graph(g) posdp = dict(posd) p1 = posdp[v1] p2 = posdp[v2] posdp[v2] = [a*(frames-j)/frames + b*j/frames
- for a,b in zip(p2,p1)]
def animate_vertex_deletion(g, v, frames = 12, **kwds):
- kwds2 = dict(kwds) if 'vertex_colors' in kwds:
- cs = dict(kwds['vertex_colors']) for c, vs in kwds['vertex_colors'].items():
- if v in vs:
- vs2 = list(vs) vs2.remove(v) cs[c] = vs2
- if v in vs:
- kwds2 = dict(kwds)
- cs = dict(kwds['vertex_colors']) for c, vs in kwds['vertex_colors'].items():
def animate_edge_deletion(g, e, frames = 12, **kwds):
- v1, v2 = e g2 = Graph(g) g2.delete_edge(e) return [plot(g, **kwds),plot(g2, **kwds)]*int(frames/2)
def animate_glide(g, pos1, pos2, frames = 12, **kwds):
- ls = [] for j in range(frames):
- gp = Graph(g) pos = {} for v in gp.vertices():
- p1 = pos1[v] p2 = pos2[v] pos[v] = [b*j/frames + a*(frames-j)/frames
- for a,b in zip(p1,p2)]
- p1 = pos1[v] p2 = pos2[v] pos[v] = [b*j/frames + a*(frames-j)/frames
- gp = Graph(g) pos = {} for v in gp.vertices():
def medio(p1, p2):
- return tuple((a+b)/2 for a,b in zip(p1, p2))
def new_color():
- return (0.1+0.8*random(), 0.1+0.8*random(), 0.1+0.8*random())
def animate_minor(g, m, frames = 12, pause = 50, step_time = 100):
Crea una animación que muestra cómo un grafo tiene un menor m posd = dict(g.get_pos()) posg = posd.values() posm = m.get_pos().values() xmax = max(max(x for x,y in posg), max(x for x,y in posm)) ymax = max(max(y for x,y in posg), max(y for x,y in posm)) xmin = min(min(x for x,y in posg), min(x for x,y in posm)) ymin = min(min(y for x,y in posg), min(y for x,y in posm)) dd = g.minor(m) #Set colors m_colors = dict((v,new_color()) for v in m.vertices()) g_colors = dict((m_colors[k],vs)
- for k,vs in dd.items())
- set(v for vs in dd.values()
- for v in vs))
- pics.extend(animate_vertex_deletion(gg, v, frames,
- vertex_colors = g_colors))
while len(vs)>1:
- for j in xrange(1,len(vs)):
- if gg.has_edge(vs[0], vs[j]):
- break
- vertex_colors = g_colors))
- gg.add_edge(vs[0],v)
- if gg.has_edge(vs[0], vs[j]):
- for j in xrange(1,len(vs)):
- for k,vs in dd.items() )
- vertex_colors = g_colors))
- if not m.has_edge(e):
- pics.extend(animate_edge_deletion(gg, e, frames,
- vertex_colors = g_colors))
- pics.extend(animate_edge_deletion(gg, e, frames,
- ymin = ymin - 0.1, ymax = ymax + 0.1)