Skip to content

Conversation

@widcardw
Copy link
Contributor

Motivation

With the pr of manim community, we can easily use .animate method to build Animation, but we cannot change the arguments of Animations. With the set_anim_args method, we can change args of Animation. Since _AnimationBuilder will build it into MoveToTarget, we can also use path_arc or path_func and so on.

Test

class TestAnimateArgs(Scene):
    def construct(self) -> None:
        a = Circle().to_edge(LEFT)
        anim_builder = (
            a
            .animate
            .scale(3)
            .to_edge(RIGHT)
            .set_anim_args(run_time=3, time_span=(1, 2), rate_func=double_smooth, path_arc=PI/2)
        )
        self.play(anim_builder)
TestAnimateArgs.mp4

@TonyCrane TonyCrane requested a review from 3b1b September 11, 2022 04:05
@widcardw
Copy link
Contributor Author

Now you can also pass args by calling the animate method, which is borrowed from manim community. The method set_anim_args also works.

class TestAnimateArgs(Scene):
    def construct(self) -> None:
        a = Circle().to_edge(LEFT)
        anim_builder = (
            a
            .animate(run_time=3, time_span=(1, 2), rate_func=double_smooth, path_arc=PI/2)
            .scale(3)
            .to_edge(RIGHT)
        )
        self.play(anim_builder)

Or

class TestAnimateArgs(Scene):
    def construct(self) -> None:
        a = Circle().to_edge(LEFT)
        anim_builder = (
            a
            .animate
            .scale(3)
            .to_edge(RIGHT)
            .set_anim_args(run_time=3, time_span=(1, 2), rate_func=double_smooth, path_arc=PI/2)
        )
        self.play(anim_builder)

BTW, the Animation args can only be passed ONCE. You should AVOID using it like below

        anim_builder = (
            a
            .animate(run_time=3, time_span=(1, 2), rate_func=double_smooth, path_arc=PI/2)
            .scale(3)
            .set_anim_args(run_time=5)  # !!! the second time that pass the args may raise error
        )

@3b1b
Copy link
Owner

3b1b commented Sep 13, 2022

Thanks!

@3b1b 3b1b merged commit d2e570e into 3b1b:master Sep 13, 2022
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.

3 participants