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 AngleTrackerDemo(Scene):
    def construct(self):
        self.add(head("高级特效：角度随 ValueTracker 变化", "Angle / always_redraw"))
        theta = ValueTracker(50.0)
        center = LEFT * 2 + DOWN * 1.2
        base = Line(center, center + RIGHT * 4, color=GREY_B)
        moving = always_redraw(lambda: Line(
            center, center + 4 * np.array([np.cos(theta.get_value() * DEGREES),
                                           np.sin(theta.get_value() * DEGREES), 0]),
            color=YELLOW).set_stroke(width=5))
        arc = always_redraw(lambda: Angle(base, moving, radius=1.1, color=BLUE))
        val = always_redraw(lambda: Text("%.0f°" % theta.get_value(),
                                         font="Consolas", font_size=26,
                                         color=YELLOW).next_to(arc, RIGHT, buff=0.3))
        self.add(base, moving, arc, val)
        self.play(theta.animate.set_value(130.0), run_time=3.6, rate_func=there_and_back)
        self.play(FadeIn(foot("角度、圆弧与数值标注共用同一个追踪器")), run_time=0.4)
        self.wait(2.2)
