在manim中以不同速度同时播放不同动画
我知道在manim这个工具里,我可以同时播放两个或多个不同的动画,方法是使用
self.play(anim1, anim2, ... )
不过,我想找一种方法,可以同时播放不同的动画,但每个动画的速度要不一样。
举个例子:两个点应该周期性地变大和变小。下面这种方法是行不通的。(请原谅我用的这个不太专业的Python算法,这只是个简单的例子。)
from manim import *
class TwoDots(Scene):
def construct(self):
point1 = Dot(point=[-3, 0, 0], radius= 0.5)
point2 = Dot(point=[3, 0, 0], radius= 0.5)
# Define the target scales
target_scales = [1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5,
1.5, 0.5]
animations = VGroup()
# Perform the scaling animation
for scale in target_scales:
# Creating transformations for point1 and point2
transform_point1 = Transform(point1, point1.copy().scale(scale), run_time=1)
transform_point2 = Transform(point2, point2.copy().scale(scale),
run_time=2)
# Adding the visual transformations to the VGroup
animations.add(transform_point1, transform_point2)
self.play(animations)
1 个回答
0
要让动画以不同的运行时间来播放,可以这样做:
self.play(point1.animate(run_time=1).scale(0.5), point2.animate(run_time=2).scale(0.5))
如果你想要像例子中那样定期更新的动画,我建议使用 UpdateFromFunc。上面的方法在这种情况下不太适用,因为在一个 self.play(...) 调用中使用多个 animate
调用是行不通的。