Manim: run_time 动画不符合预期

Manim: run_time of animation is not as expected

我想 manim 花 4 秒动画创建扇区。整个动画虽然时长4秒,但创作部分只有一半。我试过扩展 run_time 参数,但要获得完整的 4 秒创建时间,我必须将持续时间设置为 8 秒。实际绘图在 4 秒时完成,但随后我的动画比必要的时间长 50%,而后半部分只是坐在那里什么都不做。我一定做错了什么,但我对 manim 很陌生,所以我不确定自己做错了什么。也许是 rate_func 参数。

MWE:

from manimlib.imports import *

class Circ(Scene):
    def construct(self):
        shape = Sector(color=GOLD_B,
                       fill_color=GOLD_B,
                       fill_opacity=1,
                       angle=360*DEGREES)
        self.play(ShowCreation(shape,
                               lag_ratio=0,
                               rate_func=lambda t: linear(1 - t),
                               run_time=4*2)) # because we want 4 seconds for the circle's creation

我在没有 lag_ratio 的情况下尝试过(实际上还不确定它的作用)。我在animation.py中从Uncreate那里借来了rate_func。我目前最好的猜测是这个函数占用了 run_time 参数的全部时间,但看起来只用了一半。我试过其他功能,原来Uncreatesmooth。它是不同的,但似乎仍然没有填满完整的 4 秒。

提前致谢。

问题如下,如果我们打印曲线的控制点,我们会看到以下内容:

print(shape.points)

Returns:

[[ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 3.33333333e-01 -8.16431199e-17  0.00000000e+00]
 [ 6.66666667e-01 -1.63286240e-16  0.00000000e+00]
 [ 1.00000000e+00 -2.44929360e-16  0.00000000e+00]
 [ 1.00000000e+00 -2.44929360e-16  0.00000000e+00]
 [ 1.00000000e+00 -2.61799388e-01  0.00000000e+00]
 [ 8.92226904e-01 -5.21986659e-01  0.00000000e+00]
 [ 7.07106781e-01 -7.07106781e-01  0.00000000e+00]
 [ 7.07106781e-01 -7.07106781e-01  0.00000000e+00]
 [ 5.21986659e-01 -8.92226904e-01  0.00000000e+00]
 [ 2.61799388e-01 -1.00000000e+00  0.00000000e+00]
 [-1.83697020e-16 -1.00000000e+00  0.00000000e+00]
 [-1.83697020e-16 -1.00000000e+00  0.00000000e+00]
 [-2.61799388e-01 -1.00000000e+00  0.00000000e+00]
 [-5.21986659e-01 -8.92226904e-01  0.00000000e+00]
 [-7.07106781e-01 -7.07106781e-01  0.00000000e+00]
 [-7.07106781e-01 -7.07106781e-01  0.00000000e+00]
 [-8.92226904e-01 -5.21986659e-01  0.00000000e+00]
 [-1.00000000e+00 -2.61799388e-01  0.00000000e+00]
 [-1.00000000e+00  1.22464680e-16  0.00000000e+00]
 [-1.00000000e+00  1.22464680e-16  0.00000000e+00]
 [-1.00000000e+00  2.61799388e-01  0.00000000e+00]
 [-8.92226904e-01  5.21986659e-01  0.00000000e+00]
 [-7.07106781e-01  7.07106781e-01  0.00000000e+00]
 [-7.07106781e-01  7.07106781e-01  0.00000000e+00]
 [-5.21986659e-01  8.92226904e-01  0.00000000e+00]
 [-2.61799388e-01  1.00000000e+00  0.00000000e+00]
 [ 6.12323400e-17  1.00000000e+00  0.00000000e+00]
 [ 6.12323400e-17  1.00000000e+00  0.00000000e+00]
 [ 2.61799388e-01  1.00000000e+00  0.00000000e+00]
 [ 5.21986659e-01  8.92226904e-01  0.00000000e+00]
 [ 7.07106781e-01  7.07106781e-01  0.00000000e+00]
 [ 7.07106781e-01  7.07106781e-01  0.00000000e+00]
 [ 8.92226904e-01  5.21986659e-01  0.00000000e+00]
 [ 1.00000000e+00  2.61799388e-01  0.00000000e+00]
 [ 1.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 1.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 6.66666667e-01  0.00000000e+00  0.00000000e+00]
 [ 3.33333333e-01  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]]

我们可以看到很多第一个控制点都是零向量,我们必须分析扇区源代码才能解决这个问题,我建议这样做:

class Circ(Scene):
    def construct(self):
        shape = Sector(
                       color=GOLD_B,
                       fill_color=GOLD_B,
                       fill_opacity=1,
                       stroke_width=4,
                       stroke_color=TEAL,
                       angle=360*DEGREES
        )
        shape.points = shape.points[32:-1] # <- because there are 33 zero vectors at the beginning and 1 at the end
        self.play(
            ShowCreation(
                shape,
                run_time=4,
                rate_func=lambda t: linear(1-t)
            )
        )
        self.wait()

显然,零的数量会根据我们使用的 Sector 对象而改变,所以你必须找到一种方法来过滤那些不需要的零向量,也许这可以在扇区的定义中很容易更正 class.