diff --git a/manim/mobject/graph.py b/manim/mobject/graph.py index d54c1e0457..940265ffda 100644 --- a/manim/mobject/graph.py +++ b/manim/mobject/graph.py @@ -679,8 +679,13 @@ def _populate_edge_dict( """Helper method for populating the edges of the graph.""" raise NotImplementedError("To be implemented in concrete subclasses") - def __getitem__(self: Graph, v: Hashable) -> Mobject: - return self.vertices[v] + def __getitem__(self: Graph, k: Hashable | tuple[Hashable, Hashable]) -> Mobject: + if k in self.vertices: + return self.vertices[k] + elif k in self.edges: + return self.edges[k] + else: + raise ValueError(f"Could not find {k} in vertices or edges") def _create_vertex( self, @@ -1351,6 +1356,11 @@ def construct(self): g[2].animate.move_to([-1, 1, 0]), g[3].animate.move_to([1, -1, 0]), g[4].animate.move_to([-1, -1, 0])) + self.play(LaggedStart(Wiggle(g[(1, 2)]), + Wiggle(g[(2, 3)]), + Wiggle(g[(3, 4)]), + Wiggle(g[(1, 3)]), + Wiggle(g[(1, 4)]))) self.wait() There are several automatic positioning algorithms to choose from: