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 CameraZoomDemo(MovingCameraScene):
    def construct(self):
        self.add(head("相机：缩放取景框", "camera.frame.set_width"))
        sq = Square(side_length=2.0, color=GREEN).set_fill(GREEN, opacity=0.35)
        ring = Circle(radius=2.4, color=GREY_B).set_stroke(width=2)
        self.add(ring, sq)
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.set_width(4.0), run_time=2.2)
        self.play(self.camera.frame.animate.set_width(12.0), run_time=2.2)
        self.play(Restore(self.camera.frame), run_time=1.2)
        self.play(FadeIn(foot("改变 frame 宽度即实现推近与拉远")), run_time=0.4)
        self.wait(0.8)
