from manim import *
import numpy as np
def head(cn, en):
    t = Text(cn, font="STLiti", font_size=27).to_edge(UP)
    s = Text(en, font="Consolas", font_size=20, color=YELLOW).next_to(t, DOWN, buff=0.10)
    return VGroup(t, s)
def foot(cn):
    return Text(cn, font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
class CameraRestoreDemo(MovingCameraScene):
    def construct(self):
        self.add(head("相机：保存与恢复取景状态", "save_state / Restore"))
        group = VGroup(*[Dot(radius=0.18, color=c) for c in (RED, GREEN, BLUE, YELLOW)])
        group.arrange(RIGHT, buff=1.6)
        self.add(group)
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.55).move_to(group[1]), run_time=2.2)
        self.play(self.camera.frame.animate.move_to(group[3]), run_time=1.8)
        self.play(Restore(self.camera.frame), run_time=1.6)
        self.play(FadeIn(foot("restore 让相机一步回到最初的取景状态")), run_time=0.4)
        self.wait(0.8)
