Manim:动画的运行时间不符合预期

问题描述

我希望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的情况(实际上还不确定那是什么)。我从rate_func的{​​{1}}借来了Uncreate。我目前的最佳猜测是该函数占用了animation.py参数的全部时间,但看起来只使用了一半。我尝试了其他功能,原来的run_timeUncreate。情况有所不同,但似乎并不能填满整个4秒钟。

谢谢。

解决方法

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

print(shape.points)

返回:

[[ 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]]

我们可以看到许多第一个控制点都是零向量,我们必须分析Sector源代码才能解决此问题,我建议您执行以下操作:

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 mobject的不同而变化,因此您将必须找到一种方法来在开始时过滤那些不需要的零矢量,也许这很容易更正了Sector类的定义。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...