manim - 如何控制self.play在特定时间点运行
问题描述
假设有两个 self.play 语句,第一个从 1 秒开始,我想秒从一开始正好 3 秒开始。
目前我使用 self.wait 来控制步骤:
self.wait(1)
self.play...... # first animation
self.wait(2) # because 1 + 2 = 3
self.play...... # second animation
但是,因为第一个动画需要一些时间(例如 1.5 秒)才能完成,所以实际上第二个动画将从 1 + 1.5 + 2 = 4.5 秒开始。
我怎样才能让第二个 self.play start 从一开始就在 3s 处运行?提前致谢。
解决方案
你是说,这个?
class SuccessionExample(Scene):
def construct(self):
number_line=NumberLine(x_min=-2,x_max=2)
triangle=RegularPolygon(3,start_angle=-PI/2)\
.scale(0.2)\
.next_to(number_line.get_left(),UP,buff=SMALL_BUFF)
text_1=TextMobject("1")\
.next_to(number_line.get_tick(-1),DOWN)
text_2=TextMobject("2")\
.next_to(number_line.get_tick(0),DOWN)
text_3=TextMobject("3")\
.next_to(number_line.get_tick(1),DOWN)
text_4=TextMobject("4")\
.next_to(number_line.get_tick(2),DOWN)
self.add(number_line)
self.play(ShowCreation(triangle))
self.wait(0.3)
self.play(
#The move of the triangle starts
ApplyMethod(triangle.shift,RIGHT*4,rate_func=linear,run_time=4),
AnimationGroup(
Animation(Mobject(),run_time=1),#<- one second pause
Write(text_1),lag_ratio=1 #<- then start Write animation
),
AnimationGroup(
Animation(Mobject(),run_time=2),#<- two seconds pause
Write(text_2),lag_ratio=1 #<- then start Write animation
),
AnimationGroup(
Animation(Mobject(),run_time=3),#<- three seconds pause
Write(text_3),lag_ratio=1 #<- then start Write animation
),
AnimationGroup(
Animation(Mobject(),run_time=4),#<- four seconds pause
Write(text_4),lag_ratio=1 #<- then start Write animation
),
)
self.wait()
推荐阅读
- typescript - 如何将带有连字符的属性添加到声明为 any 的 Typescript 对象
- go - 内存高效方式
- c++ - 崩溃:从类访问向量时
- python - 将动画散景图导出为 GIF
- python - 如何配置 Python 忽略主机名验证?
- asp.net - 无法从 ionic 应用程序连接到信号器集线器:访问 XMLHttpRequest ... 已被 CORS 策略阻止
- c++ - 无法从另一个函数 c++ 类访问成员
- windows - 在 Windows 上运行 docker 镜像 - docker-entrypoint.sh sourcing /docker-entrypoint-initdb.d
- python - 已弃用的 Pandas.Panel 的替代方案是什么
- excel - 从 Excel 任务窗格内的 Angular 应用程序中读取 Office 加载项清单文件的设置