[EXPERIMENTAL] Fix ManimBanner animations by modifying Mobject.become(), Mobject.get_center(), and ManimBanner.expand() (#4556)

* Fix ManimBanner animations by modifying Mobject.become(), Mobject.get_center(), and ManimBanner.expand()

* Add ManimBanner animations to test_new_rendering.py
This commit is contained in:
Francisco Manríquez Novoa 2026-02-01 17:37:05 -03:00 committed by GitHub
commit a2c04954b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View file

@ -37,6 +37,14 @@ class Test(Scene):
)
self.play(FadeOut(VGroup(hexagon, circle, star)))
@group
def manim_banner(self) -> None:
banner = ManimBanner().scale(0.5)
self.play(banner.create())
self.play(banner.expand())
self.wait(1)
self.play(Unwrite(banner))
@group
def never_run(self) -> None:
self.play(Write(Text("This should never be run")))

View file

@ -327,11 +327,13 @@ class ManimBanner(VGroup):
slide_and_uncover,
run_time=run_time * 2 / 3,
rate_func=ease_in_out_cubic,
introducer=True,
),
UpdateFromAlphaFunc(
self,
slide_back,
run_time=run_time * 1 / 3,
rate_func=smooth,
introducer=True,
),
)

View file

@ -2471,7 +2471,7 @@ class OpenGLMobject:
def get_center(self) -> np.ndarray:
"""Get center coordinates."""
return self.get_bounding_box()[1]
return self.get_bounding_box()[1].copy()
def get_center_of_mass(self):
return self.get_all_points().mean(0)
@ -2850,7 +2850,12 @@ class OpenGLMobject:
circ.become(square)
self.wait(0.5)
"""
# Manim CE Weird stretching thing which also modifies the original mobject
# TODO: ideally, only copy the Mobject when it has to be modified
# (if stretch, match_height, match_width, match_depth, or match_center are True).
# Currently, it's necessary to always copy it because the final code ported
# from 3b1b/manim seems to modify the mobject, which is an issue especially when
# applying Mobject.restore() which makes a Mobject become its saved state.
mobject = mobject.copy()
if stretch:
mobject.stretch_to_fit_height(self.height)
mobject.stretch_to_fit_width(self.width)