mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Reimplement Animation.get_sub_alpha based on lag_ratio
This commit is contained in:
parent
a2d99741f3
commit
f5bf0b39b0
1 changed files with 20 additions and 14 deletions
|
@ -16,7 +16,15 @@ class Animation(object):
|
||||||
# Does this animation add or remove a mobject form the screen
|
# Does this animation add or remove a mobject form the screen
|
||||||
"remover": False,
|
"remover": False,
|
||||||
# TODO, replace this with a single lag parameter
|
# TODO, replace this with a single lag parameter
|
||||||
"submobject_mode": "all_at_once",
|
# "submobject_mode": "all_at_once",
|
||||||
|
|
||||||
|
# If 0, the animation is applied to all submobjects
|
||||||
|
# at the same time
|
||||||
|
# If 1, it is applied to each successively.
|
||||||
|
# If 0 < lag_ratio < 1, its applied to each
|
||||||
|
# with lagged start times
|
||||||
|
"lag_ratio": 0,
|
||||||
|
# TODO, remove anything with lag_factor
|
||||||
"lag_factor": 2,
|
"lag_factor": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,19 +99,17 @@ class Animation(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_sub_alpha(self, alpha, index, num_submobjects):
|
def get_sub_alpha(self, alpha, index, num_submobjects):
|
||||||
if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]:
|
# TODO, make this more understanable, and/or combine
|
||||||
prop = float(index) / num_submobjects
|
# its functionality with AnimationGroup's method
|
||||||
if self.submobject_mode is "smoothed_lagged_start":
|
# build_animations_with_timings
|
||||||
prop = smooth(prop)
|
lag_ratio = self.lag_ratio
|
||||||
lf = self.lag_factor
|
full_length = (num_submobjects - 1) * lag_ratio + 1
|
||||||
return np.clip(lf * alpha - (lf - 1) * prop, 0, 1)
|
value = alpha * full_length
|
||||||
elif self.submobject_mode == "one_at_a_time":
|
lower = index * lag_ratio
|
||||||
lower = float(index) / num_submobjects
|
return np.clip(
|
||||||
upper = float(index + 1) / num_submobjects
|
(value - lower),
|
||||||
return np.clip((alpha - lower) / (upper - lower), 0, 1)
|
0, 1,
|
||||||
elif self.submobject_mode == "all_at_once":
|
)
|
||||||
return alpha
|
|
||||||
raise Exception("Invalid submobject mode")
|
|
||||||
|
|
||||||
def get_all_mobjects(self):
|
def get_all_mobjects(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue