A community-maintained Python framework for creating mathematical animations.
Able to pass in multiple methods with same underlying object as Scene.play args
Grant Sanderson851978a26c57
diff --git a/scene/scene.py b/scene/scene.pyindex 0f4dc3156..90067f3ae 100644--- a/scene/scene.py+++ b/scene/scene.py@@ -16,7 +16,7 @@ from camera import Camerafrom tk_scene import TkSceneRootfrom mobject import Mobjectfrom animation import Animation-from animation.transform import ApplyMethod+from animation.transform import MoveToTargetclass Scene(object):CONFIG = {@@ -181,35 +181,45 @@ class Scene(object):This animation list is built by going through the args list,and each animation is simply added, but when a mobject method- s hit, an ApplyMethod animation is built using the args that+ s hit, a MoveToTarget animation is built using the args thatfollow up until either another animation is hit, another methodis hit, or the args list runs out."""animations = []- method_state = {- "method" : None,- "args" : []+ state = {+ "curr_method" : None,+ "last_method" : None,+ "method_args" : [],}- def compile_method(state, animations):- if state["method"] is None:+ def compile_method(state):+ if state["curr_method"] is None:return- animations.append(ApplyMethod(- state["method"], *state["args"]- ))- state["method"] = None- state["args"] = []+ mobject = state["curr_method"].im_self+ if state["last_method"] and state["last_method"].im_self is mobject:+ animations.pop()+ #method should already have target then.+ else:+ mobject.target = mobject.copy()+ state["curr_method"].im_func(+ mobject.target, *state["method_args"]+ )+ animations.append(MoveToTarget(mobject))+ state["last_method"] = state["curr_method"]+ state["curr_method"] = None+ state["method_args"] = []+for arg in args:if isinstance(arg, Animation):- compile_method(method_state, animations)+ compile_method(state)animations.append(arg)elif inspect.ismethod(arg):- compile_method(method_state, animations)- method_state["method"] = arg- elif method_state["method"] is not None:- method_state["args"].append(arg)+ compile_method(state)+ state["curr_method"] = arg+ elif state["curr_method"] is not None:+ state["method_args"].append(arg)else:raise Exception("Invalid play arguments")- compile_method(method_state, animations)+ compile_method(state)return animationsdef play(self, *args, **kwargs):