A community-maintained Python framework for creating mathematical animations.
update_mobject -> interpolate_mobject for Animation, but not for ContinualAnimation
Grant Sanderson1c4ff6a556b7
diff --git a/active_projects/eop/chapter1/show_proportion.py b/active_projects/eop/chapter1/show_proportion.pyindex 449b4f918..9bb266ad2 100644--- a/active_projects/eop/chapter1/show_proportion.py+++ b/active_projects/eop/chapter1/show_proportion.py@@ -83,7 +83,7 @@ class ChangeProbability(Animation):Animation.__init__(self, prob_mob, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):p = (1 - alpha) * self.p0 + alpha * self.p1self.mobject.remove(self.mobject.prob_rect, self.mobject.prob_label)diff --git a/active_projects/eop/reusables/histograms.py b/active_projects/eop/reusables/histograms.pyindex e0799da63..35ce40a16 100644--- a/active_projects/eop/reusables/histograms.py+++ b/active_projects/eop/reusables/histograms.py@@ -263,7 +263,7 @@ class FlashThroughHistogram(Animation):return cell- def update_mobject(self,t):+ def interpolate_mobject(self,t):if t == 0:self.mobject.add(self.prototype_cell)diff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.pyindex 9cce2a9fe..5896dc154 100644--- a/manimlib/animation/animation.py+++ b/manimlib/animation/animation.py@@ -25,26 +25,25 @@ class Animation(object):def __init__(self, mobject, **kwargs):assert(isinstance(mobject, Mobject))- self.mobject = mobjectdigest_config(self, kwargs)- self.all_families_zipped = self.get_all_families_zipped()+ self.mobject = mobjectdef begin(self):- mobject = self.mobject- # Make sure it's all up to date- mobject.update()- mobject.suspend_updating()+ # mobject = self.mobject+ # # Make sure it's all up to date+ # mobject.update()+ # mobject.suspend_updating()# Keep track of where it started- self.starting_mobject = mobject.copy()+ self.starting_mobject = self.mobject.copy()self.update(0)def finish(self):self.mobject.resume_updating()+ self.update(1)def clean_up_from_scene(self, scene):if self.is_remover():scene.remove(self.mobject)- return selfdef __str__(self):if self.name:@@ -58,16 +57,19 @@ class Animation(object):digest_config(self, kwargs)return self+ def update_mobjects_alt(self, dt):+ for mob in self.get_all_mobjects():+ mob.update(dt)+def update(self, alpha):alpha = np.clip(alpha, 0, 1)- self.update_mobject(self.rate_func(alpha))+ self.interpolate_mobject(self.rate_func(alpha))- def update_mobject(self, alpha):- families = self.all_families_zipped+ def interpolate_mobject(self, alpha):+ families = self.get_all_families_zipped()for i, mobs in enumerate(families):sub_alpha = self.get_sub_alpha(alpha, i, len(families))- self.update_submobject(*list(mobs) + [sub_alpha])- return self+ self.update_submobject(*mobs, sub_alpha)def get_sub_alpha(self, alpha, index, num_submobjects):if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]:diff --git a/manimlib/animation/composition.py b/manimlib/animation/composition.pyindex a10b59cf3..8fd726a76 100644--- a/manimlib/animation/composition.py+++ b/manimlib/animation/composition.py@@ -133,7 +133,7 @@ class Succession(Animation):self.current_anim_index = indexself.current_alpha = self.critical_alphas[index]- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):if self.num_anims == 0:# This probably doesn't matter for anything, but just in case,# we want it in the future, we set current_alpha even in this case@@ -151,7 +151,7 @@ class Succession(Animation):# self.critical_alphas (which is also 1.0)if not abs(alpha - 1) < 0.001:warnings.warn(- "Rounding error not near alpha=1 in Succession.update_mobject,"+ "Rounding error not near alpha=1 in Succession.interpolate_mobject,""instead alpha = %f" % alpha)print(self.critical_alphas, alpha)@@ -269,8 +269,8 @@ class ApplyToCenters(Animation):Animation.__init__(self, Group(*mobjects), **full_kwargs)self.name = str(self) + AnimationClass.__name__- def update_mobject(self, alpha):- self.centers_container.update_mobject(alpha)+ def interpolate_mobject(self, alpha):+ self.centers_container.interpolate_mobject(alpha)center_mobs = self.centers_container.mobject.split()mobjects = self.mobject.split()for center_mob, mobject in zip(center_mobs, mobjects):diff --git a/manimlib/animation/creation.py b/manimlib/animation/creation.pyindex 42e77460f..e54dfd365 100644--- a/manimlib/animation/creation.py+++ b/manimlib/animation/creation.py@@ -119,7 +119,7 @@ class ShowIncreasingSubsets(Animation):self.all_submobs = group.submobjectsAnimation.__init__(self, group, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):n_submobs = len(self.all_submobs)index = int(alpha * n_submobs)self.mobject.submobjects = self.all_submobs[:index]diff --git a/manimlib/animation/indication.py b/manimlib/animation/indication.pyindex 004d00ee4..d824aed9e 100644--- a/manimlib/animation/indication.py+++ b/manimlib/animation/indication.py@@ -276,7 +276,7 @@ class Vibrate(Animation):for k in range(1, self.overtones + 1)])- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):time = alpha * self.run_timefamilies = list(map(Mobject.get_family,diff --git a/manimlib/animation/movement.py b/manimlib/animation/movement.pyindex f80e425e1..ca5a9d0f5 100644--- a/manimlib/animation/movement.py+++ b/manimlib/animation/movement.py@@ -55,7 +55,7 @@ class PhaseFlow(Animation):digest_config(self, kwargs, locals())Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):if hasattr(self, "last_alpha"):dt = self.virtual_time * (alpha - self.last_alpha)self.mobject.apply_function(@@ -69,6 +69,6 @@ class MoveAlongPath(Animation):digest_config(self, kwargs, locals())Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):point = self.path.point_from_proportion(alpha)self.mobject.move_to(point)diff --git a/manimlib/animation/numbers.py b/manimlib/animation/numbers.pyindex 3c6c2b5d1..d8de4d736 100644--- a/manimlib/animation/numbers.py+++ b/manimlib/animation/numbers.py@@ -21,7 +21,7 @@ class ChangingDecimal(Animation):self.diff_from_tracked_mobject = dmc - tmcAnimation.__init__(self, decimal_number_mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):self.update_number(alpha)self.update_position()diff --git a/manimlib/animation/rotation.py b/manimlib/animation/rotation.pyindex fa8f47176..022d11778 100644--- a/manimlib/animation/rotation.py+++ b/manimlib/animation/rotation.py@@ -21,8 +21,8 @@ class Rotating(Animation):def update_submobject(self, submobject, starting_submobject, alpha):submobject.points = np.array(starting_submobject.points)- def update_mobject(self, alpha):- Animation.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ Animation.interpolate_mobject(self, alpha)if self.in_place and self.about_point is None:self.about_point = self.mobject.get_center()self.mobject.rotate(diff --git a/manimlib/animation/specialized.py b/manimlib/animation/specialized.pyindex e689412f7..0566e7085 100644--- a/manimlib/animation/specialized.py+++ b/manimlib/animation/specialized.py@@ -23,8 +23,8 @@ class MoveCar(ApplyMethod):tire_radius = car.get_tires()[0].get_width() / 2self.total_tire_radians = -distance / tire_radius- def update_mobject(self, alpha):- ApplyMethod.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ ApplyMethod.interpolate_mobject(self, alpha)if alpha == 0:returnradians = alpha * self.total_tire_radiansdiff --git a/manimlib/animation/transform.py b/manimlib/animation/transform.pyindex ca8163bef..13bc7bff4 100644--- a/manimlib/animation/transform.py+++ b/manimlib/animation/transform.py@@ -25,18 +25,38 @@ class Transform(Animation):}def __init__(self, mobject, target_mobject, **kwargs):- # Copy target_mobject so as to not mess with caller- self.original_target_mobject = target_mobject- target_mobject = target_mobject.copy()- target_mobject.update()+ Animation.__init__(self, mobject, **kwargs)self.target_mobject = target_mobject-- mobject.align_data(target_mobject)- digest_config(self, kwargs)self.init_path_func()- Animation.__init__(self, mobject, **kwargs)- self.name += "To" + str(target_mobject)+ def begin(self):+ mobject = self.mobject+ target = self.target_mobject+ # Note, this potentially changes the structure+ # of both mobject and target_mobject+ mobject.align_data(target)+ super().begin()+ # Copy target_mobject so as to not mess with caller+ # self.original_target_mobject = self.target_mobject+ self.target_mobject.update()+ self.target_mobject.suspend_updating()+ self.target_copy = self.target_mobject.copy()++ def finish(self):+ super().finish()+ self.target_mobject.resume_updating()++ def clean_up_from_scene(self, scene):+ super().clean_up_from_scene(scene)+ if self.replace_mobject_with_target_in_scene:+ scene.remove(self.mobject)+ scene.add(self.target_mobject)++ def __str__(self):+ return "{}To{}".format(+ super().__str__(self),+ str(self.target_mobject)+ )def update_config(self, **kwargs):Animation.update_config(self, **kwargs)@@ -64,13 +84,6 @@ class Transform(Animation):submob.interpolate(start, end, alpha, self.path_func)return self- def clean_up_from_scene(self, scene=None):- Animation.clean_up_from_scene(self, scene)- if self.replace_mobject_with_target_in_scene and scene is not None:- scene.remove(self.mobject)- if not self.remover:- scene.add(self.original_target_mobject)-class ReplacementTransform(Transform):CONFIG = {diff --git a/manimlib/animation/update.py b/manimlib/animation/update.pyindex 21626ad35..89b88c32f 100644--- a/manimlib/animation/update.py+++ b/manimlib/animation/update.py@@ -14,12 +14,12 @@ class UpdateFromFunc(Animation):digest_config(self, kwargs, locals())Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):self.update_function(self.mobject)class UpdateFromAlphaFunc(UpdateFromFunc):- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):self.update_function(self.mobject, alpha)@@ -35,7 +35,7 @@ class MaintainPositionRelativeTo(Animation):tracked_mobject.get_critical_point(tcp)Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):target = self.tracked_mobject.get_critical_point(self.tracked_critical_point)location = self.mobject.get_critical_point(self.tracked_critical_point)self.mobject.shift(target - location + self.diff)diff --git a/manimlib/for_3b1b_videos/pi_creature_animations.py b/manimlib/for_3b1b_videos/pi_creature_animations.pyindex 4c4a15c1f..f14870ece 100644--- a/manimlib/for_3b1b_videos/pi_creature_animations.py+++ b/manimlib/for_3b1b_videos/pi_creature_animations.py@@ -114,7 +114,7 @@ class FlashThroughClass(Animation):np.random.shuffle(self.indices)Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):index = int(np.floor(alpha * self.mobject.height * self.mobject.width))for pi in self.mobject:pi.set_color(BLUE_E)diff --git a/manimlib/mobject/svg/drawings.py b/manimlib/mobject/svg/drawings.pyindex 70028d5da..11035ef56 100644--- a/manimlib/mobject/svg/drawings.py+++ b/manimlib/mobject/svg/drawings.py@@ -397,9 +397,9 @@ class ClockPassesTime(Animation):)Animation.__init__(self, clock, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):for rotation in self.hour_rotation, self.minute_rotation:- rotation.update_mobject(alpha)+ rotation.interpolate_mobject(alpha)class Bubble(SVGMobject):diff --git a/manimlib/once_useful_constructs/arithmetic.py b/manimlib/once_useful_constructs/arithmetic.pyindex 3720d798f..ea6debd82 100644--- a/manimlib/once_useful_constructs/arithmetic.py+++ b/manimlib/once_useful_constructs/arithmetic.py@@ -89,7 +89,7 @@ class FlipThroughSymbols(Animation):mobject = TexMobject(self.curr_tex).shift(start_center)Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):new_tex = self.tex_list[np.ceil(alpha * len(self.tex_list)) - 1]if new_tex != self.curr_tex:diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.pyindex 98258dd01..3d57f45e7 100644--- a/manimlib/scene/scene.py+++ b/manimlib/scene/scene.py@@ -459,6 +459,7 @@ class Scene(Container):animations = self.compile_play_args_to_animation_list(*args)curr_mobjects = self.get_mobject_family_members()+ self.mobjects_from_last_animation = []for animation in animations:# This is where kwargs to play like run_time and rate_func# get applied to all animations@@ -469,6 +470,7 @@ class Scene(Container):if mob not in curr_mobjects:self.add(mob)curr_mobjects += mob.get_family()+ self.mobjects_from_last_animation.append(mob)# Begin animationanimation.begin()@@ -479,19 +481,16 @@ class Scene(Container):self.update_frame(excluded_mobjects=moving_mobjects)static_image = self.get_frame()for t in self.get_animation_time_progression(animations):+ dt = 1 / self.camera.frame_ratefor animation in animations:animation.update(t / animation.run_time)- dt = 1 / self.camera.frame_rateself.continual_update(dt)self.update_frame(moving_mobjects, static_image)self.add_frames(self.get_frame())- self.mobjects_from_last_animation = [- anim.mobject for anim in animations- ]for animation in animations:animation.finish()-+ animation.clean_up_from_scene(self)if self.skip_animations:self.continual_update(self.get_run_time(animations))diff --git a/old_projects/WindingNumber.py b/old_projects/WindingNumber.pyindex 6489edb0f..af5855389 100644--- a/old_projects/WindingNumber.py+++ b/old_projects/WindingNumber.py@@ -542,8 +542,8 @@ class WalkerAnimation(Animation):def update_submobject(self, submobject, starting_submobject, alpha):submobject.points = np.array(starting_submobject.points)- def update_mobject(self, alpha):- Animation.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ Animation.interpolate_mobject(self, alpha)cur_x, cur_y = cur_coords = self.walk_func(alpha)cur_point = self.coords_to_point(cur_x, cur_y)self.mobject.shift(cur_point - self.mobject.walker.get_center())@@ -1318,8 +1318,8 @@ class FuncRotater(Animation):def update_submobject(self, submobject, starting_submobject, alpha):submobject.points = np.array(starting_submobject.points)- def update_mobject(self, alpha):- Animation.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ Animation.interpolate_mobject(self, alpha)angle_revs = self.rev_func(alpha)self.mobject.rotate(angle_revs * TAU,diff --git a/old_projects/brachistochrone/curves.py b/old_projects/brachistochrone/curves.pyindex 337bff78a..10738a724 100644--- a/old_projects/brachistochrone/curves.py+++ b/old_projects/brachistochrone/curves.py@@ -58,7 +58,7 @@ class SlideWordDownCycloid(Animation):self.start_times = 0.5*(1-(unit_interval))Animation.__init__(self, word_mob, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):virtual_times = 2*(alpha - self.start_times)cut_offs = [0.1,diff --git a/old_projects/brachistochrone/cycloid.py b/old_projects/brachistochrone/cycloid.pyindex 6e047069a..dde85c28e 100644--- a/old_projects/brachistochrone/cycloid.py+++ b/old_projects/brachistochrone/cycloid.py@@ -12,7 +12,7 @@ class RollAlongVector(Animation):digest_config(self, kwargs, locals())Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):d_alpha = alpha - self.last_alphaself.last_alpha = alphaself.mobject.rotate_in_place(diff --git a/old_projects/crypto.py b/old_projects/crypto.pyindex 9b2070fe9..c2f2bb231 100644--- a/old_projects/crypto.py+++ b/old_projects/crypto.py@@ -4967,7 +4967,7 @@ class Exchange(Animation):self.changed_symbols_yet = FalseAnimation.__init__(self, exchange, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):exchange = self.mobjectif alpha < 1./3:self.swap.update(3*alpha)diff --git a/old_projects/efvgt.py b/old_projects/efvgt.pyindex 173fb373b..3273bccd5 100644--- a/old_projects/efvgt.py+++ b/old_projects/efvgt.py@@ -53,8 +53,8 @@ class ConfettiSpiril(Animation):def update_submobject(self, submobject, starting_submobject, alpha):submobject.points = np.array(starting_submobject.points)- def update_mobject(self, alpha):- Animation.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ Animation.interpolate_mobject(self, alpha)angle = alpha*self.num_spirils*2*np.pivert_shift = alpha*self.total_vert_shiftdiff --git a/old_projects/eola/chapter11.py b/old_projects/eola/chapter11.pyindex b2c489d50..9a51f71df 100644--- a/old_projects/eola/chapter11.py+++ b/old_projects/eola/chapter11.py@@ -858,7 +858,7 @@ class ShowSlopes(Animation):line.save_state()Animation.__init__(self, line, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):f = self.graph.point_from_proportionlow, high = list(map(f, np.clip([alpha-self.dx, alpha+self.dx], 0, 1)))slope = (high[1]-low[1])/(high[0]-low[0])diff --git a/old_projects/hilbert/section2.py b/old_projects/hilbert/section2.pyindex d3844fa16..af344bb6a 100644--- a/old_projects/hilbert/section2.py+++ b/old_projects/hilbert/section2.py@@ -745,7 +745,7 @@ class VaryCircles(Animation):digest_locals(self)Animation.__init__(self, Mobject(), **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):radius = self.radius + 0.9*self.radius*np.sin(1.5*np.pi*alpha)self.mobject = Mobject(*self.scene.get_circles_and_points(self.input_value-radius,diff --git a/old_projects/inventing_math.py b/old_projects/inventing_math.pyindex 3a507343a..a02268a3b 100644--- a/old_projects/inventing_math.py+++ b/old_projects/inventing_math.py@@ -131,7 +131,7 @@ class FlipThroughNumbers(Animation):mobject = TexMobject(str(self.current_number)).shift(start_center)Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):new_number = self.function(self.start + int(alpha *(self.end-self.start)))diff --git a/old_projects/lost_lecture.py b/old_projects/lost_lecture.pyindex 681f914c4..a8a2cd21a 100644--- a/old_projects/lost_lecture.py+++ b/old_projects/lost_lecture.py@@ -90,7 +90,7 @@ class ShowWord(Animation):self.stroke_width = word.get_stroke_width()Animation.__init__(self, word, run_time=run_time, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):word = self.mobjectstroke_width = self.stroke_widthcount = int(alpha * len(word))diff --git a/old_projects/music_and_measure.py b/old_projects/music_and_measure.pyindex 954597295..2cbf776dd 100644--- a/old_projects/music_and_measure.py+++ b/old_projects/music_and_measure.py@@ -143,7 +143,7 @@ class Vibrate(Animation):self.func = funcAnimation.__init__(self, Mobject1D(color = self.color), **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):self.mobject.reset_points()epsilon = self.mobject.epsilonself.mobject.add_points([@@ -532,7 +532,7 @@ class FlashOnXProximity(Animation):self.close_mobjects = close_mobjectsAnimation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):for mob in self.close_mobjects:if np.min(np.abs(mob.points[:,0] - self.x_val)) < 0.1:self.mobject.set_color()diff --git a/old_projects/nn/part2.py b/old_projects/nn/part2.pyindex 2b3e35a5f..ce0f0c41e 100644--- a/old_projects/nn/part2.py+++ b/old_projects/nn/part2.py@@ -575,8 +575,8 @@ class FunctionMinmization(GraphScene):self.wait(10)class ChangingDecimalWithColor(ChangingDecimal):- def update_mobject(self, alpha):- ChangingDecimal.update_mobject(self, alpha)+ def interpolate_mobject(self, alpha):+ ChangingDecimal.interpolate_mobject(self, alpha)num = self.number_update_func(alpha)self.decimal_number.set_fill(interpolate_color(BLACK, WHITE, 0.5+num*0.5),@@ -984,7 +984,7 @@ class IntroduceCostFunction(PreviewLearning):])term_updates.append(ChangingDecimal(sum_term, sum_update))for update in term_updates:- update.update_mobject(0)+ update.interpolate_mobject(0)target_vect = 0.1*np.random.random(10)target_vect[3] = 0.97diff --git a/old_projects/pi_day.py b/old_projects/pi_day.pyindex 1468bd564..771ef3c5b 100644--- a/old_projects/pi_day.py+++ b/old_projects/pi_day.py@@ -24,7 +24,7 @@ class ArcLengthChange(Animation):self.new_angle = new_angleAnimation.__init__(self,mobject,**kwargs)- def update_mobject(self,alpha):+ def interpolate_mobject(self,alpha):angle = interpolate(self.old_angle, self.new_angle, alpha)self.mobject.angle = angleself.mobject.generate_points()@@ -38,7 +38,7 @@ class LabelTracksLine(Animation):self.buff = buffAnimation.__init__(self,mobject,**kwargs)- def update_mobject(self,alpha):+ def interpolate_mobject(self,alpha):line_center = self.line.get_center()line_end = self.line.points[-1]v = line_end - line_centerdiff --git a/old_projects/triangle_of_power/intro.py b/old_projects/triangle_of_power/intro.pyindex 416ff56d1..c5247428f 100644--- a/old_projects/triangle_of_power/intro.py+++ b/old_projects/triangle_of_power/intro.py@@ -30,7 +30,7 @@ class TrigAnimation(Animation):self.center = mobject.get_center()Animation.__init__(self, mobject, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):theta = 2*np.pi*alphacircle_point = np.cos(theta)*RIGHT+np.sin(theta)*UP+self.centerpoints = [diff --git a/old_projects/waves.py b/old_projects/waves.pyindex f977acda4..a95e202ff 100644--- a/old_projects/waves.py+++ b/old_projects/waves.py@@ -202,7 +202,7 @@ class WavePacket(Animation):]Animation.__init__(self, self.vects, **kwargs)- def update_mobject(self, alpha):+ def interpolate_mobject(self, alpha):packet_center = interpolate(self.wave_packet_start,self.wave_packet_end,