Merge pull request #2147 from osMrPigHead/fix-animation-time_span

fix(animation): `time_span` doesn't work for mobjects with submobjects
This commit is contained in:
Grant Sanderson 2024-08-26 08:20:11 -07:00 committed by GitHub
commit f86245517d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -62,9 +62,6 @@ class Animation(object):
if self.time_span is not None:
start, end = self.time_span
self.run_time = max(end, self.run_time)
self.rate_func = squish_rate_func(
self.rate_func, start / self.run_time, end / self.run_time,
)
self.mobject.set_animating_status(True)
self.starting_mobject = self.create_starting_mobject()
if self.suspend_mobject_updating:
@ -150,9 +147,15 @@ class Animation(object):
"""
self.interpolate(alpha)
def time_spanned_alpha(self, alpha: float) -> float:
if self.time_span is not None:
start, end = self.time_span
return clip(alpha * self.run_time - start, 0, end - start) / (end - start)
return alpha
def interpolate_mobject(self, alpha: float) -> None:
for i, mobs in enumerate(self.families):
sub_alpha = self.get_sub_alpha(alpha, i, len(self.families))
sub_alpha = self.get_sub_alpha(self.time_spanned_alpha(alpha), i, len(self.families))
self.interpolate_submobject(*mobs, sub_alpha)
def interpolate_submobject(

View file

@ -48,7 +48,7 @@ class Rotating(Animation):
for key in sm1.pointlike_data_keys:
sm1.data[key][:] = sm2.data[key]
self.mobject.rotate(
self.rate_func(alpha) * self.angle,
self.rate_func(self.time_spanned_alpha(alpha)) * self.angle,
axis=self.axis,
about_point=self.about_point,
about_edge=self.about_edge,