Kill config in fading

This commit is contained in:
Grant Sanderson 2022-12-14 11:27:00 -08:00
parent 98a969242a
commit f6858778c4

View file

@ -12,19 +12,14 @@ from manimlib.utils.rate_functions import there_and_back
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Callable
from manimlib.mobject.mobject import Mobject from manimlib.mobject.mobject import Mobject
from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.scene.scene import Scene from manimlib.scene.scene import Scene
DEFAULT_FADE_LAG_RATIO = 0
class Fade(Transform): class Fade(Transform):
CONFIG = {
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
}
def __init__( def __init__(
self, self,
mobject: Mobject, mobject: Mobject,
@ -38,10 +33,6 @@ class Fade(Transform):
class FadeIn(Fade): class FadeIn(Fade):
CONFIG = {
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
}
def create_target(self) -> Mobject: def create_target(self) -> Mobject:
return self.mobject return self.mobject
@ -54,11 +45,19 @@ class FadeIn(Fade):
class FadeOut(Fade): class FadeOut(Fade):
CONFIG = { def __init__(
"remover": True, self,
# Put it back in original state when done mobject: Mobject,
"final_alpha_value": 0, remover: bool = True,
} final_alpha_value: float = 0.0, # Put it back in original state when done,
**kwargs
):
super().__init__(
mobject,
remover=remover,
final_alpha_value=final_alpha_value,
**kwargs
)
def create_target(self) -> Mobject: def create_target(self) -> Mobject:
result = self.mobject.copy() result = self.mobject.copy()
@ -69,7 +68,7 @@ class FadeOut(Fade):
class FadeInFromPoint(FadeIn): class FadeInFromPoint(FadeIn):
def __init__(self, mobject: Mobject, point: np.ndarray, **kwargs): def __init__(self, mobject: Mobject, point: np.ndarray[int, np.dtype[np.float64]], **kwargs):
super().__init__( super().__init__(
mobject, mobject,
shift=mobject.get_center() - point, shift=mobject.get_center() - point,
@ -79,7 +78,7 @@ class FadeInFromPoint(FadeIn):
class FadeOutToPoint(FadeOut): class FadeOutToPoint(FadeOut):
def __init__(self, mobject: Mobject, point: np.ndarray, **kwargs): def __init__(self, mobject: Mobject, point: np.ndarray[int, np.dtype[np.float64]], **kwargs):
super().__init__( super().__init__(
mobject, mobject,
shift=point - mobject.get_center(), shift=point - mobject.get_center(),
@ -89,18 +88,20 @@ class FadeOutToPoint(FadeOut):
class FadeTransform(Transform): class FadeTransform(Transform):
CONFIG = { def __init__(
"stretch": True, self,
"dim_to_match": 1, mobject: Mobject,
} target_mobject: Mobject,
stretch: bool = True,
def __init__(self, mobject: Mobject, target_mobject: Mobject, **kwargs): dim_to_match: int = 1,
self.to_add_on_completion = target_mobject
mobject.save_state()
super().__init__(
Group(mobject, target_mobject.copy()),
**kwargs **kwargs
) ):
self.to_add_on_completion = target_mobject
self.stretch = stretch
self.dim_to_match = dim_to_match
mobject.save_state()
super().__init__(Group(mobject, target_mobject.copy()), **kwargs)
def begin(self) -> None: def begin(self) -> None:
self.ending_mobject = self.mobject.copy() self.ending_mobject = self.mobject.copy()
@ -147,9 +148,12 @@ class VFadeIn(Animation):
""" """
VFadeIn and VFadeOut only work for VMobjects, VFadeIn and VFadeOut only work for VMobjects,
""" """
CONFIG = { def __init__(self, vmobject: VMobject, suspend_mobject_updating: bool = False, **kwargs):
"suspend_mobject_updating": False, super().__init__(
} vmobject,
suspend_mobject_updating=suspend_mobject_updating,
**kwargs
)
def interpolate_submobject( def interpolate_submobject(
self, self,
@ -166,11 +170,19 @@ class VFadeIn(Animation):
class VFadeOut(VFadeIn): class VFadeOut(VFadeIn):
CONFIG = { def __init__(
"remover": True, self,
# Put it back in original state when done vmobject: VMobject,
"final_alpha_value": 0, remover: bool = True,
} final_alpha_value: float = 0.0,
**kwargs
):
super().__init__(
vmobject,
remover=remover,
final_alpha_value=final_alpha_value,
**kwargs
)
def interpolate_submobject( def interpolate_submobject(
self, self,
@ -182,9 +194,18 @@ class VFadeOut(VFadeIn):
class VFadeInThenOut(VFadeIn): class VFadeInThenOut(VFadeIn):
CONFIG = { def __init__(
"rate_func": there_and_back, self,
"remover": True, vmobject: VMobject,
# Put it back in original state when done rate_func: Callable[[float], float] = there_and_back,
"final_alpha_value": 0.5, remover: bool = True,
} final_alpha_value: float = 0.5,
**kwargs
):
super().__init__(
vmobject,
rate_func=rate_func,
remover=remover,
final_alpha_value=final_alpha_value,
**kwargs
)