'How can I animate simultaneously all the graph points inside Manim?
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().
Solution 1:[1]
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.
Solution 2:[2]
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:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GameDungeon |
| Solution 2 | Antizana |
