Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(animation): time_span doesn't work for mobjects with submobjects#2147

Merged
3b1b merged 2 commits into3b1b:masterfrom
osMrPigHead:fix-animation-time_span
Aug 26, 2024
Merged

fix(animation): time_span doesn't work for mobjects with submobjects#2147
3b1b merged 2 commits into3b1b:masterfrom
osMrPigHead:fix-animation-time_span

Conversation

@osMrPigHead
Copy link

Motivation / 修改原因

time_span doesn't work for animations of mobjects with submobjects, such as DashedLine.
DashedLine 这样含有多个子物件的图形的动画无法正确处理 time_span

Proposed changes / 修改内容

  • add method time_spanned_alpha in Animation to calculate the animation progress instead of changing rate_func when begin is called
    Animation 类中添加了计算动画进度的方法 time_spanned_alpha,专门用来计算存在 time_span 时的动画进度,而不在调用 begin 时改变 rate_func
  • since Rotating also uses rate_func to decide the animation progress in interpolate_mobject, changes of rotation.py are made to correspond
    由于 Rotating 类的 interpolate_mobject 也是用 rate_func 计算动画进度,为了保持一致还修改了 rotation.py

Test / 测试

Code / 代码:

from manimlib import *


class TestScene(Scene):
    def construct(self) -> None:
        self.play(ShowCreation(Line((-1, 1, 0), (-1, -1, 0)), time_span=(0, 2)),
                  ShowCreation(DashedLine((1, 1, 0), (1, -1, 0)), time_span=(0.7, 2.7)))
        self.wait()

We hope the dashed line on the right side start to show later than the solid line on the left side.
右侧动画应比左侧晚开始。

Result / 结果:
After this change: (obviously the right one start later)
修改后:(右侧动画开始更晚)
2
Before this change: (two animations seem to start at the same time)
修改前:(两侧动画几乎同时开始)
1

@3b1b 3b1b merged commit f862455 into 3b1b:master Aug 26, 2024
@3b1b
Copy link
Owner

3b1b commented Aug 26, 2024

Good fix, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants