def compile_animations(self, *args, **kwargs): """ Creates _MethodAnimations from any _AnimationBuilders and updates animation kwargs with kwargs passed to play(). Parameters ---------- *args : Tuple[:class:`Animation`] Animations to be played. **kwargs Configuration for the call to play(). Returns ------- Tuple[:class:`Animation`] Animations to be played. """ animations = [] for arg in args: try: animations.append(prepare_animation(arg)) except TypeError: if inspect.ismethod(arg): raise TypeError( "Passing Mobject methods to Scene.play is no longer" " supported. Use Mobject.animate instead.") else: raise TypeError( f"Unexpected argument {arg} passed to Scene.play().") for animation in animations: for k, v in kwargs.items(): setattr(animation, k, v) return animations
def __init__(self, *animations: Animation, **kwargs): digest_config(self, kwargs) self.animations = [prepare_animation(anim) for anim in animations] if self.group is None: self.group = Group(*remove_list_redundancies( [anim.mobject for anim in animations])) self.init_run_time() Animation.__init__(self, self.group, **kwargs)
def anims_from_play_args(self, *args, **kwargs) -> list[Animation]: """ Each arg can either be an animation, or a mobject method followed by that methods arguments (and potentially follow by a dict of kwargs for that method). This animation list is built by going through the args list, and each animation is simply added, but when a mobject method s hit, a MoveToTarget animation is built using the args that follow up until either another animation is hit, another method is hit, or the args list runs out. """ animations = [] state = { "curr_method": None, "last_method": None, "method_args": [], } def compile_method(state): if state["curr_method"] is None: return mobject = state["curr_method"].__self__ if state["last_method"] and state[ "last_method"].__self__ is mobject: animations.pop() # method should already have target then. else: mobject.generate_target() # if len(state["method_args"]) > 0 and isinstance( state["method_args"][-1], dict): method_kwargs = state["method_args"].pop() else: method_kwargs = {} state["curr_method"].__func__(mobject.target, *state["method_args"], **method_kwargs) animations.append(MoveToTarget(mobject)) state["last_method"] = state["curr_method"] state["curr_method"] = None state["method_args"] = [] for arg in args: if inspect.ismethod(arg): compile_method(state) state["curr_method"] = arg elif state["curr_method"] is not None: state["method_args"].append(arg) elif isinstance(arg, Mobject): raise Exception(""" I think you may have invoked a method you meant to pass in as a Scene.play argument """) else: try: anim = prepare_animation(arg) except TypeError: raise TypeError( f"Unexpected argument {arg} passed to Scene.play()") compile_method(state) animations.append(anim) compile_method(state) for animation in animations: # This is where kwargs to play like run_time and rate_func # get applied to all animations animation.update_config(**kwargs) return animations