ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.7k stars 1.83k forks source link

Scaling animation breaks when combined with color change - Group elements don't scale properly #4009

Closed Nico3369 closed 2 weeks ago

Nico3369 commented 2 weeks ago

Here's the issue we're encountering with Manim animations: We're trying to create a quiz interface where when the correct answer is selected, we want to:

Scale up the answer button (1.20) Change the color of a circle from red (#fc033f) to green (#32CD32) Scale back down slightly (0.95)

All elements (circle, text, background) are properly grouped:

pythonCopyself.circle_group = VGroup(self.white_circle, self.red_circle, self.letter_text)
self.main_group = VGroup(
    self.rectangle_group,
    self.circle_group,
    self.text_group
)

When we try to animate both the color change and scaling simultaneously:

pythonCopyself.scene.play(
    self.main_group.animate.scale(1.20, about_point=anchor_point),
    self.red_circle.animate.set_fill(color="#32CD32"),
    run_time=0.3,
    rate_func=rate_functions.linear
)

The color changes but the scaling animation doesn't work properly on the colored element. We've tested this behavior with:

Different shapes (circles, rectangles) Different grouping structures Different color values Transform() instead of set_fill()

Each time, when we combine a color change with scaling in the same play(), the element changes color but doesn't scale with its group. Is there a way to properly animate both color change and scaling simultaneously in Manim? We want to achieve a smooth, single animation where the element changes color while scaling with its group. Any insights would be greatly appreciated!

behackl commented 2 weeks ago

Animations cannot be combined like that: the animate syntax generates a current snapshot and the target after applying the specified function, then interpolates between the snapshot and the target. You supply two different animation targets for the red_circle, which cannot be resolved.

Animate all members of your group individually or use UpdateFromAlphaFunc (or generally updaters) to build your animation.