from manim import *
class DotWithAxes(Scene):
    """4. 在坐标系里移动点：c2p(x, y) 把数学坐标换成屏幕坐标。
    0.21 里 coords_to_point 是 c2p 的别名，两者等价；
    点落在函数上要先算出对应的 y，再换成屏幕位置。
    """
    def construct(self):
        title = Text("4. 坐标系中的动点 c2p", font="STLiti", font_size=32).to_edge(UP)
        axes = Axes(x_range=[0, 4, 1], y_range=[0, 6, 1],
                    x_length=9, y_length=5.2, tips=False)
        labels = axes.get_axis_labels(Text("x", font_size=24), Text("y", font_size=24))
        p1, p2 = axes.c2p(1, 1), axes.c2p(2, 4)
        dot = Dot(p1, color=YELLOW, radius=0.16)
        guide = DashedLine(p1, p2, color=GREY, stroke_width=2)
        self.play(FadeIn(title), run_time=0.6)
        self.play(FadeIn(axes), FadeIn(labels), run_time=1.0)
        self.play(Create(guide), FadeIn(dot), run_time=0.8)
        self.play(dot.animate.move_to(p2), run_time=2.0)
        note = Text("coords_to_point(1, 1) == c2p(1, 1)，数学坐标 → 屏幕坐标",
                    font="STLiti", font_size=21, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.6)
