from manim import *
FONT = "STLiti"
V1 = [0, 1, 2, 3, 4, 5, 6, 7, 8]
E1 = [(0, 1), (0, 2), (0, 3), (1, 4), (1, 5), (2, 6), (2, 7), (3, 8)]
V2 = [2, 7, 6, 0, 3, 1, 8, 5, 4]
E2 = [(2, 7), (2, 6), (2, 0), (0, 3), (0, 1), (3, 8), (1, 5), (1, 4)]
COL = [YELLOW, RED, GREEN, BLUE, PURPLE, ORANGE, TEAL, MAROON]
CFG = {"color": WHITE, "radius": 0.30}
class DiGraphExample(Scene):
    def construct(self):
        lab1 = {i: Text(str(i), font=FONT, font_size=26, color=BLACK) for i in V1}
        lab2 = {i: Text(str(i), font=FONT, font_size=26, color=BLACK) for i in V2}
        ecfg1 = {e: {"color": COL[i % len(COL)], "stroke_width": 5} for i, e in enumerate(E1)}
        ecfg2 = {e: {"color": COL[i % len(COL)], "stroke_width": 5} for i, e in enumerate(E2)}
        g = DiGraph(V1, E1, layout="tree", root_vertex=0, layout_scale=3.0,
                    labels=lab1, vertex_config=CFG, edge_config=ecfg1).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)
        g2 = DiGraph(V2, E2, layout="tree", root_vertex=2, layout_scale=3.0,
                     labels=lab2, vertex_config=CFG, edge_config=ecfg2).scale(1.2)
        head2 = Text("root_vertex = 2", font="Consolas", font_size=30, color=YELLOW).to_corner(UL, buff=0.4)
        self.play(FadeOut(g), run_time=0.6)
        self.remove(head)
        self.play(FadeIn(head2), FadeIn(g2), run_time=1.4)
        self.wait(1.6)
