0

我正在尝试学习如何使用manim. 我一直在看我认为是标准的教程。我现在从 manim 的文档(不是教程)中获取一些代码。

我正在运行的代码是这样的(取自第一个示例,但添加了导入命令):

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/ 中。您可以通过将不同的目录写入 media_dir.txt 来更改此行为。

1:横幅

2:复杂变换场景

3:CountInBinaryTo256

4:CountInDecimal

5:CountInTernary

6:计数场景

7:离散图形场景

8:外部动画场景

9:阶乘基础

10:图形场景

ETC

25:方形到圆形

ETC

选择与所需场景/参数相对应的数字。

(对多个条目使用逗号分隔列表)

选择:

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

4

2 回答 2

0

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

  1. 打开manimlib/extract_scene.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. 保存更改并重试。

关于这个问题的更多信息在这里

于 2019-07-24T18:04:51.663 回答
0

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

于 2019-07-22T18:01:52.520 回答