mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Able to pass in multiple methods with same underlying object as Scene.play args
This commit is contained in:
parent
61d9a2f6a1
commit
851978a26c
1 changed files with 28 additions and 18 deletions
|
@ -16,7 +16,7 @@ from camera import Camera
|
||||||
from tk_scene import TkSceneRoot
|
from tk_scene import TkSceneRoot
|
||||||
from mobject import Mobject
|
from mobject import Mobject
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
from animation.transform import ApplyMethod
|
from animation.transform import MoveToTarget
|
||||||
|
|
||||||
class Scene(object):
|
class Scene(object):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
@ -181,35 +181,45 @@ class Scene(object):
|
||||||
|
|
||||||
This animation list is built by going through the args list,
|
This animation list is built by going through the args list,
|
||||||
and each animation is simply added, but when a mobject method
|
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 that
|
||||||
follow up until either another animation is hit, another method
|
follow up until either another animation is hit, another method
|
||||||
is hit, or the args list runs out.
|
is hit, or the args list runs out.
|
||||||
"""
|
"""
|
||||||
animations = []
|
animations = []
|
||||||
method_state = {
|
state = {
|
||||||
"method" : None,
|
"curr_method" : None,
|
||||||
"args" : []
|
"last_method" : None,
|
||||||
|
"method_args" : [],
|
||||||
}
|
}
|
||||||
def compile_method(state, animations):
|
def compile_method(state):
|
||||||
if state["method"] is None:
|
if state["curr_method"] is None:
|
||||||
return
|
return
|
||||||
animations.append(ApplyMethod(
|
mobject = state["curr_method"].im_self
|
||||||
state["method"], *state["args"]
|
if state["last_method"] and state["last_method"].im_self is mobject:
|
||||||
))
|
animations.pop()
|
||||||
state["method"] = None
|
#method should already have target then.
|
||||||
state["args"] = []
|
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:
|
for arg in args:
|
||||||
if isinstance(arg, Animation):
|
if isinstance(arg, Animation):
|
||||||
compile_method(method_state, animations)
|
compile_method(state)
|
||||||
animations.append(arg)
|
animations.append(arg)
|
||||||
elif inspect.ismethod(arg):
|
elif inspect.ismethod(arg):
|
||||||
compile_method(method_state, animations)
|
compile_method(state)
|
||||||
method_state["method"] = arg
|
state["curr_method"] = arg
|
||||||
elif method_state["method"] is not None:
|
elif state["curr_method"] is not None:
|
||||||
method_state["args"].append(arg)
|
state["method_args"].append(arg)
|
||||||
else:
|
else:
|
||||||
raise Exception("Invalid play arguments")
|
raise Exception("Invalid play arguments")
|
||||||
compile_method(method_state, animations)
|
compile_method(state)
|
||||||
return animations
|
return animations
|
||||||
|
|
||||||
def play(self, *args, **kwargs):
|
def play(self, *args, **kwargs):
|
||||||
|
|
Loading…
Add table
Reference in a new issue