mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Add time_span option to Animation
This commit is contained in:
parent
fddb0b29e1
commit
a6fcfa3b40
2 changed files with 11 additions and 1 deletions
|
@ -6,6 +6,7 @@ from manimlib.mobject.mobject import _AnimationBuilder
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.rate_functions import smooth
|
from manimlib.utils.rate_functions import smooth
|
||||||
|
from manimlib.utils.rate_functions import squish_rate_func
|
||||||
from manimlib.utils.simple_functions import clip
|
from manimlib.utils.simple_functions import clip
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
@ -23,6 +24,7 @@ DEFAULT_ANIMATION_LAG_RATIO = 0
|
||||||
class Animation(object):
|
class Animation(object):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"run_time": DEFAULT_ANIMATION_RUN_TIME,
|
"run_time": DEFAULT_ANIMATION_RUN_TIME,
|
||||||
|
"time_span": None, # Tuple of times, between which the animation will run
|
||||||
"rate_func": smooth,
|
"rate_func": smooth,
|
||||||
"name": None,
|
"name": None,
|
||||||
# Does this animation add or remove a mobject form the screen
|
# Does this animation add or remove a mobject form the screen
|
||||||
|
@ -53,6 +55,12 @@ class Animation(object):
|
||||||
# played. As much initialization as possible,
|
# played. As much initialization as possible,
|
||||||
# especially any mobject copying, should live in
|
# especially any mobject copying, should live in
|
||||||
# this method
|
# this method
|
||||||
|
if self.time_span is not None:
|
||||||
|
start, end = self.time_span
|
||||||
|
self.run_time = max(end, self.run_time)
|
||||||
|
self.rate_func = squish_rate_func(
|
||||||
|
self.rate_func, start / self.run_time, end / self.run_time,
|
||||||
|
)
|
||||||
self.mobject.set_animating_status(True)
|
self.mobject.set_animating_status(True)
|
||||||
self.starting_mobject = self.create_starting_mobject()
|
self.starting_mobject = self.create_starting_mobject()
|
||||||
if self.suspend_mobject_updating:
|
if self.suspend_mobject_updating:
|
||||||
|
@ -166,6 +174,8 @@ class Animation(object):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_run_time(self) -> float:
|
def get_run_time(self) -> float:
|
||||||
|
if self.time_span:
|
||||||
|
return max(self.run_time, self.time_span[1])
|
||||||
return self.run_time
|
return self.run_time
|
||||||
|
|
||||||
def set_rate_func(self, rate_func: Callable[[float], float]):
|
def set_rate_func(self, rate_func: Callable[[float], float]):
|
||||||
|
|
|
@ -479,7 +479,7 @@ class Scene(object):
|
||||||
return times
|
return times
|
||||||
|
|
||||||
def get_run_time(self, animations: Iterable[Animation]) -> float:
|
def get_run_time(self, animations: Iterable[Animation]) -> float:
|
||||||
return np.max([animation.run_time for animation in animations])
|
return np.max([animation.get_run_time() for animation in animations])
|
||||||
|
|
||||||
def get_animation_time_progression(
|
def get_animation_time_progression(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Add table
Reference in a new issue