如何使用 ManimCE 让数学对象从屏幕左上角进入场景?

问题描述 投票:0回答:1

我尝试了几种不同的方法,包括:.move_to()、.shift()和.to_edge(UP + LEFT),但是我正在制作动画的正弦波一直出现在屏幕中央,我需要它才能进入场景从屏幕左上角开始向下移动到屏幕中间。

这是我最近的尝试:

from manim import *


class SineWave(Scene):
    def get_sine_wave(self, dx=0):
        return FunctionGraph(
            lambda x: np.sin(4*x + dx),
            x_range=[-2, 2]
        )

    def construct(self):
         sine_function = self.get_sine_wave()
        d_theta = ValueTracker(0)

        def update_wave(func):
            func.become(
                self.get_sine_wave(dx=d_theta.get_value())
            )
            return func
   
        sine_function.add_updater(update_wave)

        sine_function.shift(2*LEFT+ UP)
        self.add(sine_function)
    
        self.play(Create(sine_function))
        self.play(d_theta.animate.increment_value(4 * PI), rate_func=linear)
        self.wait()

任何帮助将不胜感激。

python-3.x manim
1个回答
0
投票

使用

add_updater()
功能,您始终可以覆盖移动操作。这是一个解决方案,我将其放入
get_sine_wave()
fct:

from manim import *

class SineWave(Scene):
    def get_sine_wave(self, dx=0):
        return FunctionGraph(lambda x: np.sin(4 * x + dx), x_range=[-2, 2]).to_edge(UL)

    def construct(self):
        sine_function = self.get_sine_wave()
        d_theta = ValueTracker(0)

        def update_wave(func):
            func.become(self.get_sine_wave(dx=d_theta.get_value()))
            return func

        sine_function.add_updater(update_wave)

        self.play(Create(sine_function))
        self.play(d_theta.animate.increment_value(4 * PI), rate_func=linear)
        self.wait()

请注意,

FunctionGraph
旨在使用视频的整个长度,请参阅doc。在创建它之前也没有必要
add
sine_function

© www.soinside.com 2019 - 2024. All rights reserved.