试着理解我和manim的菜单是从哪里来的

2024-09-24 20:31:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力学习如何使用manim。我一直在研究我认为是标准的tutorial。我现在从manim的documentation中获取一些代码(不是教程)。你知道吗

我运行的代码如下(取自第一个示例,但添加了import命令):

from manimlib.imports import *

class SquareToCircle(Scene):
    def construct(self):
        circle = Circle()
        square = Square()
        square.flip(RIGHT)
        square.rotate(-3 * TAU / 8)
        circle.set_fill(PINK, opacity=0.5)

        self.play(ShowCreation(square))
        self.play(Transform(square, circle))
        self.play(FadeOut(square))

我从命令行运行它

$ manim SquareToCircle.py

Media will be stored in ./media/. You can change this behavior by writing a different directory to media_dir.txt.

1: Banner

2: ComplexTransformationScene

3: CountInBinaryTo256

4: CountInDecimal

5: CountInTernary

6: CountingScene

7: DiscreteGraphScene

8: ExternallyAnimatedScene

9: FactorialBase

10: GraphScene

etc

25: SquareToCircle

etc

Choose number corresponding to desired scene/arguments.

(Use comma separated list for multiple entries)

Choice(s):

当我选择25时,它运行并产生预期的输出。但是其他的选择从何而来呢?有没有办法避免他们出现?你知道吗


Tags: to代码importselfplay标准documentationetc
2条回答

我认为出现菜单是因为您没有在命令行中指定要渲染的场景。您可以在一个python文件中创建多个场景,场景的名称就是您所称的类。试试$ manim SquareToCircle.py SquareToCircle。 我认为菜单是一些示例文件中的场景。你知道吗

要仅查看文件中的场景,请执行以下操作:

  1. 打开manimlib/extract_场景.py文件
  2. 替换is_child_scene方法,这是您应该拥有的方法:
def is_child_scene(obj, module):
    if not inspect.isclass(obj):
        return False
    if not issubclass(obj, Scene):
        return False
    if obj == Scene:
        return False
    return True

有了这个:

def is_child_scene(obj, module):
    if not inspect.isclass(obj):
        return False
    if not issubclass(obj, Scene):
        return False
    if obj == Scene:
        return False
    # Add this conditional
    # |
    # v
    if not obj.__module__.startswith(module.__name__):
        return False
    return True
  1. 保存更改并重试。你知道吗

有关此问题的详细信息here。你知道吗

相关问题 更多 >