2019-02-09 09:08:57 -08:00
|
|
|
from manimlib.animation.animation import Animation
|
|
|
|
from manimlib.animation.transform import Transform
|
2020-06-07 12:23:08 -07:00
|
|
|
from manimlib.constants import ORIGIN
|
2019-02-09 09:08:57 -08:00
|
|
|
from manimlib.utils.bezier import interpolate
|
2019-03-22 11:50:16 -07:00
|
|
|
from manimlib.utils.rate_functions import there_and_back
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
2019-03-16 22:13:09 -07:00
|
|
|
DEFAULT_FADE_LAG_RATIO = 0
|
2019-02-11 22:30:51 -08:00
|
|
|
|
|
|
|
|
2020-12-04 08:14:15 -08:00
|
|
|
class Fade(Transform):
|
2019-02-09 09:08:57 -08:00
|
|
|
CONFIG = {
|
2019-02-11 22:30:51 -08:00
|
|
|
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
2019-02-09 09:08:57 -08:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:14:15 -08:00
|
|
|
def __init__(self, mobject, shift=ORIGIN, scale=1, **kwargs):
|
|
|
|
self.shift_vect = shift
|
|
|
|
self.scale_factor = scale
|
2020-06-07 12:23:08 -07:00
|
|
|
super().__init__(mobject, **kwargs)
|
|
|
|
|
2019-02-09 09:08:57 -08:00
|
|
|
|
2020-12-04 08:14:15 -08:00
|
|
|
class FadeIn(Fade):
|
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()
|
2020-06-07 12:23:08 -07:00
|
|
|
start.set_opacity(0)
|
2020-12-04 08:14:15 -08:00
|
|
|
start.scale(1.0 / self.scale_factor)
|
|
|
|
start.shift(-self.shift_vect)
|
2019-02-09 10:09:45 -08:00
|
|
|
return start
|
2019-02-09 09:08:57 -08:00
|
|
|
|
|
|
|
|
2020-12-04 08:14:15 -08:00
|
|
|
class FadeOut(Fade):
|
|
|
|
CONFIG = {
|
|
|
|
"remover": True,
|
|
|
|
# Put it back in original state when done
|
|
|
|
"final_alpha_value": 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
def create_target(self):
|
|
|
|
result = self.mobject.copy()
|
|
|
|
result.set_opacity(0)
|
|
|
|
result.shift(self.shift_vect)
|
|
|
|
result.scale(self.scale_factor)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2019-03-19 22:28:13 -07:00
|
|
|
class FadeInFromPoint(FadeIn):
|
|
|
|
def __init__(self, mobject, point, **kwargs):
|
2020-12-04 08:14:15 -08:00
|
|
|
super().__init__(mobject, shift=mobject.get_center() - point, **kwargs)
|
2019-03-19 22:28:13 -07:00
|
|
|
|
|
|
|
|
2021-01-03 14:39:45 -08:00
|
|
|
# Below will be deprecated
|
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 = {
|
2020-08-30 16:00:42 -07:00
|
|
|
"remover": True,
|
|
|
|
# Put it back in original state when done
|
|
|
|
"final_alpha_value": 0,
|
2019-02-09 09:08:57 -08:00
|
|
|
}
|
|
|
|
|
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)
|
2019-03-22 11:50:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
class VFadeInThenOut(VFadeIn):
|
|
|
|
CONFIG = {
|
|
|
|
"rate_func": there_and_back,
|
|
|
|
"remover": True,
|
2020-08-30 16:00:42 -07:00
|
|
|
# Put it back in original state when done
|
|
|
|
"final_alpha_value": 0.5,
|
2019-03-22 11:50:16 -07:00
|
|
|
}
|