diff --git a/active_projects/eop/chapter1/show_proportion.py b/active_projects/eop/chapter1/show_proportion.py index 449b4f91..9bb266ad 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.p1 self.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.py index e0799da6..35ce40a1 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.py index 9cce2a9f..5896dc15 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 = mobject digest_config(self, kwargs) - self.all_families_zipped = self.get_all_families_zipped() + self.mobject = mobject def 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 self def __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.py index a10b59cf..8fd726a7 100644 --- a/manimlib/animation/composition.py +++ b/manimlib/animation/composition.py @@ -133,7 +133,7 @@ class Succession(Animation): self.current_anim_index = index self.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.py index 42e77460..e54dfd36 100644 --- a/manimlib/animation/creation.py +++ b/manimlib/animation/creation.py @@ -119,7 +119,7 @@ class ShowIncreasingSubsets(Animation): self.all_submobs = group.submobjects Animation.__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.py index 004d00ee..d824aed9 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_time families = list(map( Mobject.get_family, diff --git a/manimlib/animation/movement.py b/manimlib/animation/movement.py index f80e425e..ca5a9d0f 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.py index 3c6c2b5d..d8de4d73 100644 --- a/manimlib/animation/numbers.py +++ b/manimlib/animation/numbers.py @@ -21,7 +21,7 @@ class ChangingDecimal(Animation): self.diff_from_tracked_mobject = dmc - tmc Animation.__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.py index fa8f4717..022d1177 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.py index e689412f..0566e708 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() / 2 self.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: return radians = alpha * self.total_tire_radians diff --git a/manimlib/animation/transform.py b/manimlib/animation/transform.py index ca8163be..13bc7bff 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.py index 21626ad3..89b88c32 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.py index 4c4a15c1..f14870ec 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.py index 70028d5d..11035ef5 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.py index 3720d798..ea6debd8 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.py index 98258dd0..3d57f45e 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 animation animation.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_rate for animation in animations: animation.update(t / animation.run_time) - dt = 1 / self.camera.frame_rate self.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.py index 6489edb0..af585538 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.py index 337bff78..10738a72 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.py index 6e047069..dde85c28 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_alpha self.last_alpha = alpha self.mobject.rotate_in_place( diff --git a/old_projects/crypto.py b/old_projects/crypto.py index 9b2070fe..c2f2bb23 100644 --- a/old_projects/crypto.py +++ b/old_projects/crypto.py @@ -4967,7 +4967,7 @@ class Exchange(Animation): self.changed_symbols_yet = False Animation.__init__(self, exchange, **kwargs) - def update_mobject(self, alpha): + def interpolate_mobject(self, alpha): exchange = self.mobject if alpha < 1./3: self.swap.update(3*alpha) diff --git a/old_projects/efvgt.py b/old_projects/efvgt.py index 173fb373..3273bccd 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.pi vert_shift = alpha*self.total_vert_shift diff --git a/old_projects/eola/chapter11.py b/old_projects/eola/chapter11.py index b2c489d5..9a51f71d 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_proportion low, 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.py index d3844fa1..af344bb6 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.py index 3a507343..a02268a3 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.py index 681f914c..a8a2cd21 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.mobject stroke_width = self.stroke_width count = int(alpha * len(word)) diff --git a/old_projects/music_and_measure.py b/old_projects/music_and_measure.py index 95459729..2cbf776d 100644 --- a/old_projects/music_and_measure.py +++ b/old_projects/music_and_measure.py @@ -143,7 +143,7 @@ class Vibrate(Animation): self.func = func Animation.__init__(self, Mobject1D(color = self.color), **kwargs) - def update_mobject(self, alpha): + def interpolate_mobject(self, alpha): self.mobject.reset_points() epsilon = self.mobject.epsilon self.mobject.add_points([ @@ -532,7 +532,7 @@ class FlashOnXProximity(Animation): self.close_mobjects = close_mobjects Animation.__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.py index 2b3e35a5..ce0f0c41 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.97 diff --git a/old_projects/pi_day.py b/old_projects/pi_day.py index 1468bd56..771ef3c5 100644 --- a/old_projects/pi_day.py +++ b/old_projects/pi_day.py @@ -24,7 +24,7 @@ class ArcLengthChange(Animation): self.new_angle = new_angle Animation.__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 = angle self.mobject.generate_points() @@ -38,7 +38,7 @@ class LabelTracksLine(Animation): self.buff = buff Animation.__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_center diff --git a/old_projects/triangle_of_power/intro.py b/old_projects/triangle_of_power/intro.py index 416ff56d..c5247428 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*alpha circle_point = np.cos(theta)*RIGHT+np.sin(theta)*UP+self.center points = [ diff --git a/old_projects/waves.py b/old_projects/waves.py index f977acda..a95e202f 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,