from manim import *
FONT = "STLiti"
V = list(range(9))
E = [(0, 1), (0, 2), (0, 3), (1, 4), (1, 5), (2, 6), (2, 7), (3, 8)]
COL = [YELLOW, RED, GREEN, BLUE, PURPLE, ORANGE, TEAL, MAROON]
ECFG = {e: {"color": COL[i % len(COL)], "stroke_width": 5} for i, e in enumerate(E)}
CFG = {"color": WHITE, "radius": 0.30}
class GraphExample(Scene):
    def construct(self):
        lab1 = {i: Text(str(i), font=FONT, font_size=26, color=BLACK) for i in V}
        g = Graph(V, E, layout="tree", root_vertex=0, layout_scale=3.0,
                  labels=lab1, vertex_config=CFG, edge_config=ECFG).scale(1.2)
        head = Text("root_vertex = 0", font="Consolas", font_size=30, color=YELLOW).to_corner(UL, buff=0.4)
        self.play(FadeIn(head), FadeIn(g), run_time=1.4)
        self.wait(0.8)
        lab2 = {i: Text(str(i), font=FONT, font_size=26, color=BLACK) for i in V}
        g2 = Graph(V, E, layout="tree", root_vertex=2, layout_scale=3.0,
                   labels=lab2, vertex_config=CFG, edge_config=ECFG).scale(1.2)
        head2 = Text("root_vertex = 2", font="Consolas", font_size=30, color=YELLOW).to_corner(UL, buff=0.4)
        self.play(Transform(g, g2), run_time=1.8)
        self.remove(head)
        self.add(head2)
        self.wait(1.6)
