0

我做了这门课:50分的螺旋变圆。

但是动画是连续的,我想同时开始。

class SpiralToCircle(Scene):
    def construct(self):
        vertices1 = range(50)
        vertices2 = range(50)
        edges = [(48, 49),(3, 4)]
        g1 = Graph(vertices1, edges, layout="spiral")
        g2 = Graph(vertices2, edges, layout="circular")

        # self.add(graph)
        self.play(Create(g1))
        self.wait(5)
        for i in vertices1:
            self.play(g1[i].animate.move_to(g2[i]))
        self.wait()

我想过这个技巧,但我返回一个错误:

self.play((g1[i].animate.move_to(g2[i])) for i in vertices1)

类型错误:意外的参数 <generator object GraphCircular.construct.. at 0x00000229667509E0> 传递给 Scene.play()。

4

2 回答 2

0

这应该有效:self.play([g1[i].animate.move_to(g2[i]) for i in vertices1])播放功能可以获取动画列表。

于 2021-04-26T23:27:48.743 回答
0

尝试解压动画列表并将它们作为参数传递给 play 方法:

self.play(*[g1[i].animate.move_to(g2[i]) for i in vertices1])

因此,代码将是:

类 SpiralToCircle(场景):

def construct(self):
    vertices1 = range(50)
    vertices2 = range(50)
    edges = [(48, 49), (3, 4)]
    g1 = Graph(vertices1, edges, layout="spiral")
    g2 = Graph(vertices2, edges, layout="circular")

    # self.add(graph)
    self.play(Create(g1))
    self.wait(5)
    self.play(*[g1[i].animate.move_to(g2[i]) for i in vertices1])
    self.wait()

生成此输出:

输出动画

于 2022-02-08T04:04:48.753 回答