-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyboard_walk.sage
42 lines (26 loc) · 1.04 KB
/
keyboard_walk.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
h.graphplot(save_pos=True)
z=h.get_pos()
anim=[]
vcolors={'green':['a'],'orange':[x for x in h.vertices() if x != 'a']}
ecolors={'blue':list(h.edges()),'green':[]}
state='a'
anim.append(h.plot(pos=z,vertex_colors=vcolors,edge_colors = ecolors))
for i in range(100):
new = choice(h.neighbors(state))
if (state,new,None) in h.edges():
ecolors['green'] = [(state,new,None)]
ecolors['blue'].remove((state,new,None))
else:
ecolors['green'] = [(new,state,None)]
ecolors['blue'].remove((new,state,None))
anim.append(h.plot(pos=z,vertex_colors=vcolors,edge_colors = ecolors))
vcolors['green']=[new]
vcolors['orange'].remove(new)
vcolors['orange'].append(state)
anim.append(h.plot(pos=z,vertex_colors=vcolors,edge_colors = ecolors))
ecolors['green'] = []
ecolors['blue'] = h.edges()
anim.append(h.plot(pos=z,vertex_colors=vcolors,edge_colors = ecolors))
state = new
final=animate(anim)
final.show(delay=20)