2019-02-09 09:08:57 -08:00
|
|
|
from manimlib.animation.animation import Animation
|
2019-02-12 09:44:26 -08:00
|
|
|
from manimlib.animation.animation import DEFAULT_ANIMATION_LAG_RATIO
|
2019-02-09 09:08:57 -08:00
|
|
|
from manimlib.animation.transform import Transform
|
2019-02-09 10:17:37 -08:00
|
|
|
from manimlib.constants import DOWN
|
2019-02-09 09:08:57 -08:00
|
|
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
|
|
|
from manimlib.utils.bezier import interpolate
|
|
|
|
|
|
|
|
|
2019-03-16 22:13:09 -07:00
|
|
|
DEFAULT_FADE_LAG_RATIO = 0
|
2019-02-11 22:30:51 -08:00
|
|
|
|
|
|
|
|
2019-02-09 09:08:57 -08:00
|
|
|
class FadeOut(Transform):
|
|
|
|
CONFIG = {
|
|
|
|
"remover": True,
|
2019-02-11 22:30:51 -08:00
|
|
|
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
2019-02-09 09:08:57 -08:00
|
|
|
}
|
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
def create_target(self):
|
|
|
|
return self.mobject.copy().fade(1)
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
def clean_up_from_scene(self, scene=None):
|
2019-02-09 11:54:15 -08:00
|
|
|
super().clean_up_from_scene(scene)
|
2019-02-09 09:08:57 -08:00
|
|
|
self.interpolate(0)
|
|
|
|
|
|
|
|
|
|
|
|
class FadeIn(Transform):
|
2019-02-11 22:30:51 -08:00
|
|
|
CONFIG = {
|
|
|
|
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
|
|
|
}
|
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
def create_target(self):
|
|
|
|
return self.mobject
|
|
|
|
|
2019-02-09 10:09:45 -08:00
|
|
|
def create_starting_mobject(self):
|
|
|
|
start = super().create_starting_mobject()
|
|
|
|
start.fade(1)
|
|
|
|
if isinstance(start, VMobject):
|
|
|
|
start.set_stroke(width=0)
|
|
|
|
start.set_fill(opacity=0)
|
|
|
|
return start
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
class FadeInFrom(Transform):
|
2019-02-09 09:08:57 -08:00
|
|
|
CONFIG = {
|
|
|
|
"direction": DOWN,
|
2019-02-12 09:44:26 -08:00
|
|
|
"lag_ratio": DEFAULT_ANIMATION_LAG_RATIO,
|
2019-02-09 09:08:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, mobject, direction=None, **kwargs):
|
2019-02-09 09:36:37 -08:00
|
|
|
if direction is not None:
|
|
|
|
self.direction = direction
|
2019-02-09 10:56:51 -08:00
|
|
|
super().__init__(mobject, **kwargs)
|
2019-02-09 09:08:57 -08:00
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
def create_target(self):
|
|
|
|
return self.mobject.copy()
|
2019-02-09 09:08:57 -08:00
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
def begin(self):
|
|
|
|
super().begin()
|
|
|
|
self.starting_mobject.shift(self.direction)
|
|
|
|
self.starting_mobject.fade(1)
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
2019-02-09 09:36:37 -08:00
|
|
|
class FadeInFromDown(FadeInFrom):
|
2019-02-09 09:08:57 -08:00
|
|
|
"""
|
2019-02-09 09:36:37 -08:00
|
|
|
Identical to FadeInFrom, just with a name that
|
|
|
|
communicates the default
|
2019-02-09 09:08:57 -08:00
|
|
|
"""
|
|
|
|
CONFIG = {
|
|
|
|
"direction": DOWN,
|
2019-02-12 09:44:26 -08:00
|
|
|
"lag_ratio": DEFAULT_ANIMATION_LAG_RATIO,
|
2019-02-09 09:08:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class FadeOutAndShift(FadeOut):
|
|
|
|
CONFIG = {
|
|
|
|
"direction": DOWN,
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, mobject, direction=None, **kwargs):
|
2019-02-09 10:09:45 -08:00
|
|
|
if direction is not None:
|
|
|
|
self.direction = direction
|
2019-02-09 10:56:51 -08:00
|
|
|
super().__init__(mobject, **kwargs)
|
2019-02-09 10:09:45 -08:00
|
|
|
|
|
|
|
def create_target(self):
|
|
|
|
target = super().create_target()
|
|
|
|
target.shift(self.direction)
|
|
|
|
return target
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class FadeOutAndShiftDown(FadeOutAndShift):
|
2019-02-09 10:09:45 -08:00
|
|
|
"""
|
|
|
|
Identical to FadeOutAndShift, just with a name that
|
|
|
|
communicates the default
|
|
|
|
"""
|
2019-02-09 09:08:57 -08:00
|
|
|
CONFIG = {
|
|
|
|
"direction": DOWN,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-09 10:09:45 -08:00
|
|
|
class FadeInFromLarge(FadeIn):
|
|
|
|
CONFIG = {
|
|
|
|
"scale_factor": 2,
|
|
|
|
}
|
|
|
|
|
2019-02-09 09:08:57 -08:00
|
|
|
def __init__(self, mobject, scale_factor=2, **kwargs):
|
2019-02-09 10:09:45 -08:00
|
|
|
if scale_factor is not None:
|
|
|
|
self.scale_factor = scale_factor
|
2019-02-09 10:56:51 -08:00
|
|
|
super().__init__(mobject, **kwargs)
|
2019-02-09 10:09:45 -08:00
|
|
|
|
|
|
|
def create_starting_mobject(self):
|
|
|
|
start = super().create_starting_mobject()
|
|
|
|
start.scale(self.scale_factor)
|
|
|
|
return start
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class VFadeIn(Animation):
|
|
|
|
"""
|
2019-02-09 10:09:45 -08:00
|
|
|
VFadeIn and VFadeOut only work for VMobjects,
|
2019-02-09 09:08:57 -08:00
|
|
|
"""
|
2019-02-09 10:09:45 -08:00
|
|
|
CONFIG = {
|
|
|
|
"suspend_mobject_updating": False,
|
|
|
|
}
|
2019-02-09 09:08:57 -08:00
|
|
|
|
2019-02-09 10:09:45 -08:00
|
|
|
def interpolate_submobject(self, submob, start, alpha):
|
|
|
|
submob.set_stroke(
|
|
|
|
opacity=interpolate(0, start.get_stroke_opacity(), alpha)
|
2019-02-09 09:08:57 -08:00
|
|
|
)
|
2019-02-09 10:09:45 -08:00
|
|
|
submob.set_fill(
|
|
|
|
opacity=interpolate(0, start.get_fill_opacity(), alpha)
|
2019-02-09 09:08:57 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class VFadeOut(VFadeIn):
|
|
|
|
CONFIG = {
|
|
|
|
"remover": True
|
|
|
|
}
|
|
|
|
|
2019-02-09 10:09:45 -08:00
|
|
|
def interpolate_submobject(self, submob, start, alpha):
|
2019-02-09 10:56:51 -08:00
|
|
|
super().interpolate_submobject(submob, start, 1 - alpha)
|