A community-maintained Python framework for creating mathematical animations.
clean_up -> clean_up_from_scene
Grant Sandersonbf3d9c9b5ab5
diff --git a/active_projects/eop/chapter1/show_proportion.py b/active_projects/eop/chapter1/show_proportion.pyindex f891dae4a..449b4f918 100644--- a/active_projects/eop/chapter1/show_proportion.py+++ b/active_projects/eop/chapter1/show_proportion.py@@ -92,9 +92,9 @@ class ChangeProbability(Animation):self.mobject.add(self.mobject.prob_rect, self.mobject.prob_label)- def clean_up(self, surrounding_scene=None):+ def clean_up_from_scene(self, scene=None):self.mobject.p = self.p1- super(ChangeProbability, self).clean_up(surrounding_scene = surrounding_scene)+ super(ChangeProbability, self).clean_up_from_scene(scene = scene)diff --git a/active_projects/eop/reusables/histograms.py b/active_projects/eop/reusables/histograms.pyindex 91c12e86e..e0799da63 100644--- a/active_projects/eop/reusables/histograms.py+++ b/active_projects/eop/reusables/histograms.py@@ -280,14 +280,14 @@ class FlashThroughHistogram(Animation):self.mobject.remove(self.prototype_cell)- def clean_up(self, surrounding_scene = None):- Animation.clean_up(self, surrounding_scene)+ def clean_up_from_scene(self, scene = None):+ Animation.clean_up_from_scene(self, scene)self.update(1)- if surrounding_scene is not None:+ if scene is not None:if self.is_remover():- surrounding_scene.remove(self.prototype_cell)+ scene.remove(self.prototype_cell)else:- surrounding_scene.add(self.prototype_cell)+ scene.add(self.prototype_cell)return selfdiff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.pyindex fb37a5a10..9cce2a9fe 100644--- a/manimlib/animation/animation.py+++ b/manimlib/animation/animation.py@@ -15,8 +15,7 @@ class Animation(object):"name": None,# Does this animation add or remove a mobject form the screen"remover": False,- # Options are lagged_start, smoothed_lagged_start,- # one_at_a_time, all_at_once+ # TODO, replace this with a single lag parameter"submobject_mode": "all_at_once","lag_factor": 2,# Used by EmptyAnimation to announce itself ignorable@@ -26,24 +25,31 @@ class Animation(object):def __init__(self, mobject, **kwargs):assert(isinstance(mobject, Mobject))- digest_config(self, kwargs, locals())+ self.mobject = mobject+ digest_config(self, kwargs)+ self.all_families_zipped = self.get_all_families_zipped()++ def begin(self):+ mobject = self.mobject# Make sure it's all up to datemobject.update()+ mobject.suspend_updating()# Keep track of where it started- self.starting_mobject = self.mobject.copy()- if self.name is None:- self.name = self.__class__.__name__ + str(self.mobject)- self.all_families_zipped = self.get_all_families_zipped()+ self.starting_mobject = mobject.copy()self.update(0)- def begin_animation(self):- pass+ def finish(self):+ self.mobject.resume_updating()- def end_animation(self):- pass+ def clean_up_from_scene(self, scene):+ if self.is_remover():+ scene.remove(self.mobject)+ return selfdef __str__(self):- return self.name+ if self.name:+ return self.name+ return self.__class__.__name__ + str(self.mobject)def copy(self):return deepcopy(self)@@ -63,22 +69,6 @@ class Animation(object):self.update_submobject(*list(mobs) + [sub_alpha])return self- def update_submobject(self, submobject, starting_sumobject, alpha):- # Typically ipmlemented by subclass- pass-- def get_all_mobjects(self):- """- Ordering must match the ording of arguments to update_submobject- """- return self.mobject, self.starting_mobject-- def get_all_families_zipped(self):- return list(zip(*list(map(- Mobject.family_members_with_points,- self.get_all_mobjects()- ))))-def get_sub_alpha(self, alpha, index, num_submobjects):if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]:prop = float(index) / num_submobjects@@ -94,6 +84,22 @@ class Animation(object):return alpharaise Exception("Invalid submobject mode")+ def update_submobject(self, submobject, starting_sumobject, alpha):+ # Typically ipmlemented by subclass+ pass++ def get_all_mobjects(self):+ """+ Ordering must match the ording of arguments to update_submobject+ """+ return self.mobject, self.starting_mobject++ def get_all_families_zipped(self):+ return list(zip(*map(+ Mobject.family_members_with_points,+ self.get_all_mobjects()+ )))+def filter_out(self, *filter_functions):self.filter_functions += filter_functionsreturn self@@ -118,10 +124,3 @@ class Animation(object):def is_remover(self):return self.remover-- def clean_up(self, surrounding_scene=None):- self.update(1)- if surrounding_scene is not None:- if self.is_remover():- surrounding_scene.remove(self.mobject)- return selfdiff --git a/manimlib/animation/composition.py b/manimlib/animation/composition.pyindex d456d7312..a10b59cf3 100644--- a/manimlib/animation/composition.py+++ b/manimlib/animation/composition.py@@ -103,7 +103,7 @@ class Succession(Animation):self.scene_mobjects_at_time[0] = Group()for i in range(self.num_anims):self.scene_mobjects_at_time[i + 1] = self.scene_mobjects_at_time[i].copy()- self.animations[i].clean_up(self.scene_mobjects_at_time[i + 1])+ self.animations[i].clean_up_from_scene(self.scene_mobjects_at_time[i + 1])self.current_alpha = 0# If self.num_anims == 0, this is an invalid index, but so it goes@@ -168,11 +168,11 @@ class Succession(Animation):self.animations[i].update(sub_alpha)self.current_alpha = alpha- def clean_up(self, *args, **kwargs):+ def clean_up_from_scene(self, *args, **kwargs):# We clean up as though we've played ALL animations, even if# clean_up is called in middle of thingsfor anim in self.animations:- anim.clean_up(*args, **kwargs)+ anim.clean_up_from_scene(*args, **kwargs)class AnimationGroup(Animation):@@ -197,9 +197,9 @@ class AnimationGroup(Animation):for anim in self.sub_anims:anim.update(alpha * self.run_time / anim.run_time)- def clean_up(self, *args, **kwargs):+ def clean_up_from_scene(self, *args, **kwargs):for anim in self.sub_anims:- anim.clean_up(*args, **kwargs)+ anim.clean_up_from_scene(*args, **kwargs)def update_config(self, **kwargs):Animation.update_config(self, **kwargs)@@ -251,9 +251,9 @@ class LaggedStart(Animation):anim.update(alpha)return self- def clean_up(self, *args, **kwargs):+ def clean_up_from_scene(self, *args, **kwargs):for anim in self.subanimations:- anim.clean_up(*args, **kwargs)+ anim.clean_up_from_scene(*args, **kwargs)class ApplyToCenters(Animation):diff --git a/manimlib/animation/creation.py b/manimlib/animation/creation.pyindex 7e5d335ad..42e77460f 100644--- a/manimlib/animation/creation.py+++ b/manimlib/animation/creation.py@@ -137,8 +137,8 @@ class FadeOut(Transform):target.fade(1)Transform.__init__(self, mobject, target, **kwargs)- def clean_up(self, surrounding_scene=None):- Transform.clean_up(self, surrounding_scene)+ def clean_up_from_scene(self, scene=None):+ Transform.clean_up_from_scene(self, scene)self.update(0)diff --git a/manimlib/animation/indication.py b/manimlib/animation/indication.pyindex 6f28c5838..004d00ee4 100644--- a/manimlib/animation/indication.py+++ b/manimlib/animation/indication.py@@ -132,8 +132,8 @@ class ShowPassingFlash(ShowPartial):lower = max(lower, 0)return (lower, upper)- def clean_up(self, *args, **kwargs):- ShowPartial.clean_up(self, *args, **kwargs)+ def clean_up_from_scene(self, *args, **kwargs):+ ShowPartial.clean_up_from_scene(self, *args, **kwargs)for submob, start_submob in self.get_all_families_zipped():submob.pointwise_become_partial(start_submob, 0, 1)diff --git a/manimlib/animation/transform.py b/manimlib/animation/transform.pyindex ad99184e2..ca8163bef 100644--- a/manimlib/animation/transform.py+++ b/manimlib/animation/transform.py@@ -7,7 +7,6 @@ from manimlib.constants import *from manimlib.mobject.mobject import Groupfrom manimlib.mobject.mobject import Mobjectfrom manimlib.utils.config_ops import digest_config-from manimlib.utils.config_ops import instantiatefrom manimlib.utils.iterables import adjacent_pairsfrom manimlib.utils.paths import path_along_arcfrom manimlib.utils.paths import straight_path@@ -65,12 +64,12 @@ class Transform(Animation):submob.interpolate(start, end, alpha, self.path_func)return self- def clean_up(self, surrounding_scene=None):- Animation.clean_up(self, surrounding_scene)- if self.replace_mobject_with_target_in_scene and surrounding_scene is not None:- surrounding_scene.remove(self.mobject)+ 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:- surrounding_scene.add(self.original_target_mobject)+ scene.add(self.original_target_mobject)class ReplacementTransform(Transform):diff --git a/manimlib/for_3b1b_videos/pi_creature_animations.py b/manimlib/for_3b1b_videos/pi_creature_animations.pyindex 6fa76f625..4c4a15c1f 100644--- a/manimlib/for_3b1b_videos/pi_creature_animations.py+++ b/manimlib/for_3b1b_videos/pi_creature_animations.py@@ -93,11 +93,11 @@ class RemovePiCreatureBubble(AnimationGroup):FadeOut(pi_creature.bubble.content),)- def clean_up(self, surrounding_scene=None):- AnimationGroup.clean_up(self, surrounding_scene)+ def clean_up_from_scene(self, scene=None):+ AnimationGroup.clean_up_from_scene(self, scene)self.pi_creature.bubble = None- if surrounding_scene is not None:- surrounding_scene.add(self.pi_creature)+ if scene is not None:+ scene.add(self.pi_creature)class FlashThroughClass(Animation):diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.pyindex 200d73038..98258dd01 100644--- a/manimlib/scene/scene.py+++ b/manimlib/scene/scene.py@@ -458,17 +458,20 @@ class Scene(Container):returnanimations = self.compile_play_args_to_animation_list(*args)+ curr_mobjects = self.get_mobject_family_members()for animation in animations:# This is where kwargs to play like run_time and rate_func# get applied to all animationsanimation.update_config(**kwargs)# Anything animated that's not already in the# scene gets added to the scene- if animation.mobject not in self.get_mobject_family_members():- self.add(animation.mobject)- # Don't call the update functions of a mobject- # being animated- animation.mobject.suspend_updating()+ mob = animation.mobject+ if mob not in curr_mobjects:+ self.add(mob)+ curr_mobjects += mob.get_family()+ # Begin animation+ animation.begin()+moving_mobjects = self.get_moving_mobjects(*animations)# Paint all non-moving objects onto the screen, so they don't@@ -482,10 +485,14 @@ class Scene(Container):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]- self.clean_up_animations(*animations)+ for animation in animations:+ animation.finish()++if self.skip_animations:self.continual_update(self.get_run_time(animations))else:@@ -498,8 +505,7 @@ class Scene(Container):def clean_up_animations(self, *animations):for animation in animations:- animation.clean_up(self)- animation.mobject.resume_updating()+ animation.clean_up_from_scene(self)return selfdef get_mobjects_from_last_animation(self):diff --git a/old_projects/clacks/question.py b/old_projects/clacks/question.pyindex 99cb4a47f..300813ae0 100644--- a/old_projects/clacks/question.py+++ b/old_projects/clacks/question.py@@ -79,11 +79,11 @@ class SlidingBlocks(VGroup):"collect_clack_data": True,}- def __init__(self, surrounding_scene, **kwargs):+ def __init__(self, scene, **kwargs):VGroup.__init__(self, **kwargs)- self.surrounding_scene = surrounding_scene- self.floor = surrounding_scene.floor- self.wall = surrounding_scene.wall+ self.scene = scene+ self.floor = scene.floor+ self.wall = scene.wallself.block1 = self.get_block(**self.block1_config)self.block2 = self.get_block(**self.block2_config)@@ -159,7 +159,7 @@ class SlidingBlocks(VGroup):DR,)- self.surrounding_scene.update_num_clacks(n_clacks)+ self.scene.update_num_clacks(n_clacks)def get_clack_data(self):ps_point = self.phase_space_point_tracker.get_location()