def clean_up_from_scene(self, scene: Scene) -> None: """Clean up the :class:`~.Scene` after finishing the animation. This includes to :meth:`~.Scene.remove` the Animation's :class:`~.Mobject` if the animation is a remover. Parameters ---------- scene The scene the animation should be cleaned up from. """ self._on_finish(scene) if self.is_remover(): scene.remove(self.mobject)
def _setup_scene(self, scene: Scene) -> None: """Setup up the :class:`~.Scene` before starting the animation. This includes to :meth:`~.Scene.add` the Animation's :class:`~.Mobject` if the animation is an introducer. Parameters ---------- scene The scene the animation should be cleaned up from. """ if scene is None: return if self.is_introducer(): scene.add(self.mobject)
def compile_play_args_to_animation_list(self, *args, **kwargs): """ Add animations so that all creatures look at the first mobject being animated with each .play call """ animations = Scene.compile_play_args_to_animation_list(self, *args, **kwargs) anim_mobjects = Group(*[a.mobject for a in animations]) all_movers = anim_mobjects.get_family() if not self.any_creatures_on_screen(): return animations creatures = self.get_on_screen_creatures() non_creature_anims = [ anim for anim in animations if len(set(anim.mobject.get_family()).intersection(creatures)) == 0 ] if len(non_creature_anims) == 0: return animations first_anim = non_creature_anims[0] main_mobject = first_anim.mobject for creature in creatures: if creature not in all_movers: animations.append(ApplyMethod( creature.look_at, main_mobject, )) return animations
def test_animationgroup_is_passing_remover_to_animations( animation_remover, animation_group_remover): scene = Scene() sqr_animation = Create(Square(), remover=animation_remover) circ_animation = Write(Circle(), remover=animation_remover) animation_group = AnimationGroup(sqr_animation, circ_animation, remover=animation_group_remover) scene.play(animation_group) scene.wait(0.1) assert sqr_animation.remover assert circ_animation.remover
def test_animationgroup_is_passing_remover_to_nested_animationgroups(): scene = Scene() sqr_animation = Create(Square()) circ_animation = Write(Circle(), remover=True) polygon_animation = Create(RegularPolygon(5)) animation_group = AnimationGroup( AnimationGroup(sqr_animation, polygon_animation), circ_animation, remover=True ) scene.play(animation_group) scene.wait(0.1) assert sqr_animation.remover assert circ_animation.remover assert polygon_animation.remover
def non_blink_wait(self, time=1, **kwargs): Scene.wait(self, time, **kwargs) return self