from manim import *
class NumberPlaneRatio(Scene):
    """3.3 同样的显示尺寸下，坐标范围不同，单位长度就不同。
    左边 x 方向被压扁（14 个单位挤进 4.5），右边 y 方向被压扁；
    老示例只上屏了 plane2，这里两个一起淡入做对照。
    """
    def construct(self):
        title = Text("不同比例的坐标轴", font="STLiti", font_size=32).to_edge(UP)
        p1 = NumberPlane(x_range=[-7, 7], y_range=[-3, 3],
                         x_length=4.5, y_length=4.5)
        p2 = NumberPlane(x_range=[-3, 3], y_range=[-7, 7],
                         x_length=4.5, y_length=4.5)
        caps = VGroup(
            Text("x: -7~7  y: -3~3  横向压缩", font="STLiti", font_size=20, color=YELLOW),
            Text("x: -3~3  y: -7~7  纵向压缩", font="STLiti", font_size=20, color=YELLOW),
        )
        planes = VGroup(p1, p2).arrange(RIGHT, buff=1.4).shift(DOWN * 0.35)
        for c, p in zip(caps, planes):
            c.next_to(p, UP, buff=0.3)
        self.play(FadeIn(title), run_time=0.6)
        self.play(LaggedStart(*[FadeIn(p) for p in planes],
                              lag_ratio=0.3, run_time=1.8))
        self.play(LaggedStart(*[FadeIn(c) for c in caps],
                              lag_ratio=0.2, run_time=1.0))
        note = Text("显示尺寸相同，坐标范围决定每格代表的数值",
                    font="STLiti", font_size=20, color=GREY).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(3.0)
