from manim import *
class ComplexPlanePoints(Scene):
    """3.2 用 n2p 把复数换成画面坐标，再标点与写标签。
    原文片段没有 import、没有 Scene，plane 与两个 Dot 也从未 self.add / self.play，
    所以渲染出来是全黑；下面给出可直接运行的完整写法。
    """
    def construct(self):
        kw = dict(font="STLiti")
        title = Text("3.2 在复数平面上标记复数点", font_size=36, color=RED, **kw).to_edge(UP, buff=0.28)
        rule = Line(LEFT * 6.6, RIGHT * 6.6, color=BLUE_B, stroke_width=3).next_to(title, DOWN, buff=0.16)
        plane = ComplexPlane(x_range=[-5, 5, 1], y_range=[-5, 5, 1],
                             x_length=8.4, y_length=5.6).add_coordinates()
        z1, z2 = 3 + 2j, -4 - 2j
        d1 = Dot(plane.n2p(z1), radius=0.13, color=YELLOW)
        d2 = Dot(plane.n2p(z2), radius=0.13, color=RED)
        l1 = Text("z = 3 + 2i", font_size=26, color=YELLOW, **kw).next_to(d1, UR, buff=0.15)
        l2 = Text("z = -4 - 2i", font_size=26, color=RED, **kw).next_to(d2, DL, buff=0.15)
        note = Text("n2p(z) 把复数转成画面坐标；p2n(点) 可反向还原成复数",
                    font_size=24, color=GREY_B, **kw).to_edge(DOWN, buff=0.25)
        self.play(FadeIn(title), FadeIn(rule), run_time=0.7)
        self.play(FadeIn(plane), run_time=1.4)
        self.play(FadeIn(d1), FadeIn(d2), run_time=0.9)
        self.play(FadeIn(l1), FadeIn(l2), run_time=0.9)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.4)
