Movement

声明

这一页翻译自elteoremadebeethoven的 manim_3feb_docs

Homotopy

class manimlib.animation.movement.Homotopy(homotopy: Callable[[float, float, float, float], Sequence[float]], mobject: Mobject, **kwargs)

homotopy 是一个从 (x, y, z, t) 到 (x’, y’, z’) 的函数。 t 的取值范围是 [0, 1], 让 mobject 根据 homotopy 计算的每个点坐标进行变换。 例子中 t = 0 时 mob 是边长为 0 的正方形, t = 1 时是边长为 2 的正方形。 与 Transform 类似,区别在于 Transform 锚点运动轨迹是直线, Homotopy 锚点运动轨迹是根据传入的 homotopy 计算的。

HomotopyExample
class HomotopyExample(Scene):
    def construct(self):
        def homotopy_fun(x, y, z, t):
            return [x * t, y * t, z]

        mob = Square()
        self.add(mob)
        self.play(Homotopy(homotopy_fun, mob))
        self.wait()

ComplexHomotopy

class manimlib.animation.movement.ComplexHomotopy(complex_homotopy: Callable[[complex, float], Sequence[float]], mobject: Mobject, **kwargs)

继承自 Homotopy。与 Homotopy 类似,就是用复数描述坐标。

ComplexHomotopyExample
class ComplexHomotopyExample(Scene):
    def construct(self):
        def complex_func(z: complex, t: float) -> complex:
            return interpolate(z, z**3, t)

        mobjects = VGroup(
            Text("Text"),
            Square(side_length=1),
        ).arrange(RIGHT, buff=2)

        self.add(mobjects)
        self.play(
            *[ComplexHomotopy(
                complex_func,
                mob
            ) for mob in mobjects]
        )
        self.wait(0.3)

PhaseFlow

class manimlib.animation.movement.PhaseFlow(function: Callable[[np.ndarray], np.ndarray], mobject: Mobject, **kwargs)
PhaseFlowExample
class PhaseFlowExample(Scene):
    def construct(self):
        def func(t):
            return t*0.5*RIGHT

        mobjects=VGroup(
            Text("Text").scale(3),
            Square(),
        ).arrange(RIGHT,buff=2)

        self.play(
            *[PhaseFlow(
                func, mob,
                run_time = 2,
            )for mob in mobjects]
        )

        self.wait()

MoveAlongPath

class manimlib.animation.movement.MoveAlongPath(mobject: Mobject, path: Mobject, **kwargs)
MoveAlongPathExample
class MoveAlongPathExample(Scene):
    def construct(self):
        line=Line(ORIGIN,RIGHT*FRAME_WIDTH,buff=1)
        line.move_to(ORIGIN)
        dot=Dot()
        dot.move_to(line.get_start())

        self.add(line,dot)
        self.play(
            MoveAlongPath(dot,line)
        )
        self.wait(0.3)