How can I animate simultaneously all the graph points inside Manim?

914 views Asked by At

I made this class : 50 points of a spiral change to a cirle.

But the animation is sequential and I would like to start it at the same time.

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()

I thought about this trick, but I returns an error :

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

TypeError: Unexpected argument <generator object GraphCircular.construct.. at 0x00000229667509E0> passed to Scene.play().

2

There are 2 answers

2
GameDungeon On

This should work: self.play([g1[i].animate.move_to(g2[i]) for i in vertices1]) The play function can take a list of animations.

0
Antizana On

Try unpacking the animation list and pass them as parameters to the play method:

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

So, the code would be:

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)
    self.play(*[g1[i].animate.move_to(g2[i]) for i in vertices1])
    self.wait()

Generating this output:

Output Animation