Compare commits
2 Commits
1085220b67
...
3c5e3e1fbe
Author | SHA1 | Date |
---|---|---|
Bibin Muttappillil | 3c5e3e1fbe | |
Bibin Muttappillil | 39684289b0 |
|
@ -3,33 +3,27 @@ from manim import *
|
|||
|
||||
class Main(Scene):
|
||||
def construct(self):
|
||||
# change
|
||||
adj_list = [[1, 2], [0, 3], [0, 3], [1, 2, 4], [3]]
|
||||
vertices = [v for v, _ in enumerate(adj_list)]
|
||||
edges = [(v, u) for v, neighs in enumerate(adj_list) for u in neighs]
|
||||
|
||||
adj_vis = Graph(vertices, edges, labels=True, layout='spring', vertex_config={"fill_color": WHITE, "fill_opacity": 0.5})
|
||||
|
||||
self.play(Create(adj_vis))
|
||||
self.wait()
|
||||
|
||||
visited = [False for _ in adj_list]
|
||||
|
||||
print(adj_vis[0])
|
||||
|
||||
def dfs(v):
|
||||
self.play(Indicate(adj_vis[v]))
|
||||
if visited[v]:
|
||||
return
|
||||
|
||||
visited[v] = True
|
||||
self.play(ApplyMethod(adj_vis[v].set_opacity, 1.0))
|
||||
|
||||
for u in adj_list[v]:
|
||||
self.play(Indicate(adj_vis.edges[(v, u)]), Indicate(adj_vis.edges[(u, v)]))
|
||||
dfs(u)
|
||||
|
||||
|
||||
self.play(ApplyMethod(adj_vis[v].set_color, BLUE))
|
||||
|
||||
dfs(0)
|
||||
|
||||
|
||||
vertices = [v for v, _ in enumerate(adj_list)]
|
||||
edges = [(v, u) for v, neighs in enumerate(adj_list) for u in neighs]
|
||||
adj_vis = Graph(vertices, edges, labels=True, layout='spring').move_to(3*LEFT)
|
||||
code = Code(file_name="dfs-manim.py", language="python").move_to(3*RIGHT).scale(0.5)
|
||||
|
||||
#self.play(Create(adj_vis), Create(code))
|
||||
#self.wait()
|
||||
self.add(adj_vis, code)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
from manim import *
|
||||
|
||||
import networkx as nx
|
||||
|
||||
class Tree(Scene):
|
||||
def construct(self):
|
||||
vertices = list(range(1, 25))
|
||||
edges = []
|
||||
for v in vertices[1:]:
|
||||
edges.append((v // 2, v))
|
||||
|
||||
self.play(Create(Graph(vertices, edges, labels=True, layout="tree", layout_config={"vertex_spacing": (1.0, 1.0)}, root_vertex=1)))
|
||||
self.wait(2)
|
Loading…
Reference in New Issue