mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 05:24:22 +08:00
Introduced update_submobject to Animation. I'd be surprised if this didn't break something.
This commit is contained in:
@ -18,6 +18,9 @@ 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
|
||||
"submobject_mode" : "lagged_start",
|
||||
}
|
||||
def __init__(self, mobject, **kwargs):
|
||||
mobject = instantiate(mobject)
|
||||
@ -31,8 +34,6 @@ class Animation(object):
|
||||
self.update(0)
|
||||
|
||||
def update_config(self, **kwargs):
|
||||
if "path_arc" in kwargs:
|
||||
kwargs["path_arc"]
|
||||
digest_config(self, kwargs)
|
||||
return self
|
||||
|
||||
@ -49,6 +50,40 @@ class Animation(object):
|
||||
alpha = 1.0
|
||||
self.update_mobject(self.rate_func(alpha))
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
families = self.get_all_families_zipped()
|
||||
for i, mobs in enumerate(families):
|
||||
sub_alpha = self.get_sub_alpha(alpha, i, len(families))
|
||||
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_families_zipped(self):
|
||||
"""
|
||||
Ordering must match the ording of arguments to update_submobject
|
||||
"""
|
||||
return zip(
|
||||
self.mobject.submobject_family(),
|
||||
self.starting_mobject.submobject_family()
|
||||
)
|
||||
|
||||
def get_sub_alpha(self, alpha, index, num_submobjects):
|
||||
if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]:
|
||||
prop = float(index)/num_submobjects
|
||||
if self.submobject_mode is "smoothed_lagged_start":
|
||||
prop = smooth(prop)
|
||||
return np.clip(2*alpha - prop, 0, 1)
|
||||
elif self.submobject_mode == "one_at_a_time":
|
||||
lower = float(index)/num_submobjects
|
||||
upper = float(index+1)/num_submobjects
|
||||
return np.clip((alpha-lower)/(upper-lower), 0, 1)
|
||||
elif self.submobject_mode == "all_at_once":
|
||||
return alpha
|
||||
raise Exception("Invalid submobject mode")
|
||||
|
||||
def filter_out(self, *filter_functions):
|
||||
self.filter_functions += filter_functions
|
||||
return self
|
||||
@ -71,11 +106,7 @@ class Animation(object):
|
||||
|
||||
def set_name(self, name):
|
||||
self.name = name
|
||||
return self
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
#Typically ipmlemented by subclass
|
||||
pass
|
||||
return self
|
||||
|
||||
def is_remover(self):
|
||||
return self.remover
|
||||
|
Reference in New Issue
Block a user