如何使用 manim 从非场景 class 播放动画?
How can I play an animation from a non-Scene class using manim?
我想做一个神经网络动画,我在网上找到了一个 class,我根据自己的需要对其进行了修改。基本上,class 看起来像:
class NeuralNetworkMobject(VGroup):
...
...
def change_edge_color(...):
edge = random.choice(n1.edges_out) # n1.edges_out is a VGroup, and edge is Line
# I want to play the edge fade in animation from this method.
# I've tried to do:
NeuralNetworkScene.play(FadeIn(edge)) # NeuralNetworkScene is the actual scene
但是,程序报错,说:
File "neural.py", line 171, in set_neuron_edge_color
NeuralScene.play(FadeIn(n_edge))
File "/usr/local/lib/python3.9/site-packages/manimlib/scene/scene.py", line 845, in wrapper
self.update_skipping_status()
AttributeError: 'FadeIn' object has no attribute 'update_skipping_status'
如何从非场景播放动画class?
谢谢,
所以我尽我所能,包括实例化主场景然后尝试播放动画(你显然不应该这样做)直接访问 Scene.play() 方法(这没有用任何一个)。因此,作为解决方案,我想出了:
class MainScene(Scene):
def construct(self):
...
neurons = NeuralNetworkMobject()
your_animation_function(neurons)
def your_animation_function(self, neurons):
self.play(FadeIn(neurons))
...
虽然这种方法确实解决了问题,但出于好奇,我想问是否可以从非场景播放动画class?
谢谢,
我想做一个神经网络动画,我在网上找到了一个 class,我根据自己的需要对其进行了修改。基本上,class 看起来像:
class NeuralNetworkMobject(VGroup):
...
...
def change_edge_color(...):
edge = random.choice(n1.edges_out) # n1.edges_out is a VGroup, and edge is Line
# I want to play the edge fade in animation from this method.
# I've tried to do:
NeuralNetworkScene.play(FadeIn(edge)) # NeuralNetworkScene is the actual scene
但是,程序报错,说:
File "neural.py", line 171, in set_neuron_edge_color
NeuralScene.play(FadeIn(n_edge))
File "/usr/local/lib/python3.9/site-packages/manimlib/scene/scene.py", line 845, in wrapper
self.update_skipping_status()
AttributeError: 'FadeIn' object has no attribute 'update_skipping_status'
如何从非场景播放动画class?
谢谢,
所以我尽我所能,包括实例化主场景然后尝试播放动画(你显然不应该这样做)直接访问 Scene.play() 方法(这没有用任何一个)。因此,作为解决方案,我想出了:
class MainScene(Scene):
def construct(self):
...
neurons = NeuralNetworkMobject()
your_animation_function(neurons)
def your_animation_function(self, neurons):
self.play(FadeIn(neurons))
...
虽然这种方法确实解决了问题,但出于好奇,我想问是否可以从非场景播放动画class?
谢谢,