from manim import *
class NumberPlaneCurves(Scene):
    """3.4 plot_parametric_curve 返回 ParametricFunction，
    必须 self.play(Create(...)) 才会上屏；老示例把 g1/g2 算出来就结束，视频是黑的。
    函数返回 [x, y] 形式的二维点，t_range 第三位是采样步长。
    """
    def construct(self):
        title = Text("在坐标平面上绘制函数图像", font="STLiti", font_size=32).to_edge(UP)
        plane = NumberPlane(x_range=[-4, 4, 1], y_range=[-16, 16, 4],
                            x_length=6, y_length=6)
        parabola = plane.plot_parametric_curve(
            lambda x: [x, x ** 2], t_range=[-3.5, 3.5, 0.01],
            color=YELLOW, stroke_width=4)
        cubic = plane.plot_parametric_curve(
            lambda x: [x, x ** 3], t_range=[-2.5, 2.5, 0.01],
            color=RED, stroke_width=4)
        legend = VGroup(
            Text("y = x²  抛物线（黄）", font="STLiti", font_size=21, color=YELLOW),
            Text("y = x³  三次曲线（红）", font="STLiti", font_size=21, color=RED),
        ).arrange(DOWN, aligned_edge=LEFT, buff=0.16).to_corner(DL)
        self.play(FadeIn(title), run_time=0.6)
        self.play(FadeIn(plane), run_time=1.0)
        self.play(LaggedStart(Create(parabola), Create(cubic),
                              lag_ratio=0.5, run_time=2.4))
        self.play(FadeIn(legend), run_time=0.8)
        self.wait(2.8)
