from manim import *
class SpeedDotDemo(Scene):
    def construct(self):
        title = Text("ChangeSpeed：用 speedinfo 分段控制速度", font="STLiti", font_size=30).to_edge(UP)
        self.play(FadeIn(title), run_time=0.6)
        d1 = Dot(color=BLUE, radius=0.17).shift(LEFT * 5 + UP * 1.2)
        d2 = Dot(color=RED, radius=0.17).shift(RIGHT * 5 + DOWN * 1.2)
        self.play(FadeIn(d1), FadeIn(d2), run_time=0.6)
        self.play(ChangeSpeed(d1.animate(run_time=2).shift(RIGHT * 5),
                              speedinfo={0.2: 0.5, 0.3: 2, 0.8: 0.5}, rate_func=linear))
        self.play(ChangeSpeed(d2.animate(run_time=2).shift(LEFT * 5),
                              speedinfo={0.2: 2, 0.3: 0.5, 0.8: 2}, rate_func=linear))
        note = Text("蓝点先慢后快再慢，红点先快后慢再快", font="STLiti", font_size=21, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.4)
        self.wait(1.2)
