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 ChangeSpeedGraph(Scene):
    def construct(self):
        self.add(head("图像交点处减速强调", "ChangeSpeed / Axes.plot"))
        axes = Axes(x_range=[-3, 3, 1], y_range=[-1, 5, 1], x_length=8, y_length=4.6,
                    axis_config={"color": GREY_B}).shift(DOWN * 0.4)
        graph = axes.plot(lambda x: x**2, x_range=[-2, 2], color=BLUE).set_stroke(width=5)
        dot = Dot(axes.c2p(-2, 4), color=YELLOW, radius=0.13)
        self.add(axes, graph, dot)
        self.play(MoveAlongPath(dot, graph, rate_func=linear), run_time=2.0)
        self.play(Flash(dot, color=YELLOW, line_length=0.25), run_time=1.2)
        self.play(ChangeSpeed(Wait(1.6), speedinfo={0: 1.2, 0.5: 0.2, 1: 1.0}))
        self.play(dot.animate.move_to(axes.c2p(0, 0)), run_time=1.2)
        self.play(FadeIn(foot("在关键帧放慢速度，观众才看得清拐点与交点")), run_time=0.4)
        self.wait(1.4)
