from manim import *
import numpy as np
import manim.animation.movement as _movement
_movement.VMobject = VMobject
class VectHomoDemo(Scene):
    def construct(self):
        title = Text("SmoothedVectorizedHomotopy：向量场均匀减弱", font="STLiti", font_size=28).to_edge(UP)
        self.play(FadeIn(title), run_time=0.6)
        field = ArrowVectorField(lambda p: np.array([p[0], p[1], 0]) * 0.25,
                                 x_range=[-2.5, 2.5, 1], y_range=[-2, 2, 1], color=BLUE)
        self.play(Create(field), run_time=1.0)
        def homotopy(x, y, z, t):
            return ((1 - 0.7 * t) * x, (1 - 0.7 * t) * y, 0)
        self.play(SmoothedVectorizedHomotopy(homotopy, field), run_time=2.6)
        note = Text("同伦函数把每个箭头按比例缩短，实现平滑衰减", font="STLiti", font_size=21, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.4)
        self.wait(1.6)
