from manim import *
class AlwaysRedrawDemo(Scene):
    def construct(self):
        title = Text("always_redraw：每帧重建", font="STLiti", font_size=34).to_edge(UP)
        self.add(title)
        ax = Axes(x_range=[0, 5, 1], y_range=[-2, 2, 1], x_length=9, y_length=3.5).shift(DOWN * 0.4)
        sine = ax.plot(lambda x: np.sin(x), color=BLUE)
        alpha = ValueTracker(0)
        dot = always_redraw(lambda: Dot(ax.c2p(alpha.get_value(), np.sin(alpha.get_value())), color=YELLOW, radius=0.12))
        line = always_redraw(lambda: DashedLine(ax.c2p(alpha.get_value(), np.sin(alpha.get_value())), ax.c2p(alpha.get_value(), -2), color=GREY))
        self.add(ax, sine, dot, line)
        self.play(alpha.animate.set_value(5), rate_func=linear, run_time=5)
        self.wait(1)
