Added final_alpha_value parameter to Animation for things like FadeOut

This commit is contained in:
Grant Sanderson 2020-08-30 16:00:42 -07:00
parent 852e840523
commit 35a2ade954
2 changed files with 13 additions and 5 deletions

View file

@ -17,6 +17,8 @@ class Animation(object):
"name": None,
# Does this animation add or remove a mobject form the screen
"remover": False,
# What to enter into the update function upon completion
"final_alpha_value": 1,
# If 0, the animation is applied to all submobjects
# at the same time
# If 1, it is applied to each successively.
@ -55,7 +57,7 @@ class Animation(object):
self.interpolate(0)
def finish(self):
self.interpolate(1)
self.interpolate(self.final_alpha_value)
self.mobject.cleanup_from_animation()
if self.suspend_mobject_updating:
self.mobject.resume_updating()

View file

@ -14,6 +14,8 @@ class FadeOut(Transform):
CONFIG = {
"remover": True,
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
# Put it back in original state when done
"final_alpha_value": 0,
}
def __init__(self, mobject, to_vect=ORIGIN, **kwargs):
@ -26,9 +28,9 @@ class FadeOut(Transform):
result.shift(self.to_vect)
return result
def clean_up_from_scene(self, scene=None):
super().clean_up_from_scene(scene)
self.interpolate(0)
# def clean_up_from_scene(self, scene=None):
# super().clean_up_from_scene(scene)
# self.interpolate(0)
class FadeIn(Transform):
@ -113,7 +115,9 @@ class VFadeIn(Animation):
class VFadeOut(VFadeIn):
CONFIG = {
"remover": True
"remover": True,
# Put it back in original state when done
"final_alpha_value": 0,
}
def interpolate_submobject(self, submob, start, alpha):
@ -124,4 +128,6 @@ class VFadeInThenOut(VFadeIn):
CONFIG = {
"rate_func": there_and_back,
"remover": True,
# Put it back in original state when done
"final_alpha_value": 0.5,
}