from manim import *
FONT = "STLiti"
V = list(range(9))
E = [(0, 2), (0, 3), (0, 4), (1, 3), (1, 4), (2, 5), (2, 6), (3, 5),
     (3, 6), (3, 7), (4, 6), (4, 8), (5, 7), (5, 8), (6, 7), (6, 8)]
PARTS = [[0, 1], [2, 3, 4], [5, 6], [7, 8]]
COL = [RED, GREEN, BLUE, YELLOW, PURPLE, ORANGE]
LAB = {i: Text(str(i), font=FONT, font_size=26, color=BLACK) for i in V}
class GraphExample(Scene):
    def construct(self):
        head = VGroup(Text("层状图：", font=FONT, font_size=32, color=YELLOW),
                      Text("partitions", font="Consolas", font_size=30, color=YELLOW),
                      Text(" 四层", font=FONT, font_size=32, color=YELLOW)).arrange(RIGHT, buff=0.08).to_edge(UP)
        cfg = {ee: {"color": COL[i % len(COL)], "stroke_width": 6} for i, ee in enumerate(E)}
        g = Graph(V, E, layout="partite", partitions=PARTS, layout_scale=3.0,
                  labels=LAB, vertex_config={"color": WHITE, "radius": 0.30}, edge_config=cfg).scale(1.2)
        self.play(FadeIn(head), run_time=0.6)
        self.play(FadeIn(VGroup(*g.vertices.values())), run_time=1.2)
        self.play(Create(VGroup(*g.edges.values())), run_time=1.8)
        self.wait(2.0)
