Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify anim schedule call #30

Open
AzurIce opened this issue Mar 14, 2025 · 5 comments
Open

Simplify anim schedule call #30

AzurIce opened this issue Mar 14, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@AzurIce
Copy link
Owner

AzurIce commented Mar 14, 2025

This is TOO LONG:

timeline.play(
    rects[j + 1]
        .transform(|data| {
            data.shift(-shift_right)
                .set_fill_color(manim::BLUE_C.with_alpha(0.5));
        })
        .with_duration(anim_step_duration)
        .with_rate_func(linear)
        .apply(),
);

If custom attributes can be applied to expressions, then we can implement a macro to write it like:

timeline.play(
    #[param(duration = anim_step_duration, rate_func = linear, apply)]
    rects[j + 1].transform(|data| {
        data.shift(-shift_right)
            .set_fill_color(manim::BLUE_C.with_alpha(0.5));
    }),
);

However it is not supported now, see rust-lang/rust#54727.

To support optional param, another solution is by macro_rules!, but it does not have easy support of "unordered optional params":

timeline.play(
    param!(rects[j + 1].transform(|data| {
        data.shift(-shift_right)
            .set_fill_color(manim::BLUE_C.with_alpha(0.5));
    }), duration = anim_step_duration, rate_func = linear, apply = true),
);

Or, work on another direction:

rects[j + 1]
    .transform(|data| {
        data.shift(-shift_right)
            .set_fill_color(manim::BLUE_C.with_alpha(0.5));
    })
    .with_duration(anim_step_duration)
    .with_rate_func(linear)
    .apply()
    .play();
@AzurIce AzurIce added enhancement New feature or request help wanted Extra attention is needed labels Mar 14, 2025
@AzurIce
Copy link
Owner Author

AzurIce commented Mar 14, 2025

Or, we use drop to play it, use discard explicitly to mark not to play?

@suterberg
Copy link

拆分动画帧与运行,创建动画帧和play分开也没啥影响吧,还好区分,要么就是函数式贯彻到底,最后一个比较好

let anmi= rects[j + 1]
        .transform(|data| {
            data.shift(-shift_right)
                .set_fill_color(manim::BLUE_C.with_alpha(0.5));
        })
        .with_duration(anim_step_duration)
        .with_rate_func(linear)
        .apply(),
timeline.play(
   anmi
);

@AzurIce
Copy link
Owner Author

AzurIce commented Mar 18, 2025

拆分动画帧与运行,创建动画帧和play分开也没啥影响吧,还好区分,要么就是函数式贯彻到底,最后一个比较好

好ww

其实最开始设计 play 通过 timeline.play 来进行是因为这样阅读代码的时候比较容易看到哪里对时间线进行了变更。

不过如果一个 transform 内的变更较小的话(比如只更改了颜色/只更改了位置),看起来层级结构就太多了。可能单独给 transform 写一个 builder,会好一些嘛?类似这样:

let transform_anim = rects[j + 1]
    .begin_transform() // sth like `TransformBuilder`
    .shift(-shift_right)
    .set_fill_color(manim::BLUE_C.with_alpha(0.5));
    .finish() // construct an normal `AnimSchedule`
    .apply();

timeline.play(
    anim
        .with_duration(anim_step_duration)
        .with_rate_func(linear)
);

@suterberg
Copy link

分开的话,更好抓重点,逻辑性也强一些,emm 类似编程范式吧,没必要非得一个步骤就完成,上边这样的就挺好,数据准备和执行分开,内存释放rust不用管,写着也方便

@AzurIce
Copy link
Owner Author

AzurIce commented Mar 18, 2025

分开的话,更好抓重点,逻辑性也强一些,emm 类似编程范式吧,没必要非得一个步骤就完成,上边这样的就挺好,数据准备和执行分开,内存释放rust不用管,写着也方便

嗯嗯确实~感谢反馈~(^.^)

@AzurIce AzurIce added enhancement New feature or request and removed enhancement New feature or request help wanted Extra attention is needed labels Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants