mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Change arguments for Fading so that you can pass in shift and/or scale to FadeIn and FadeOut, aimed at increased readibility and flexibility
This commit is contained in:
parent
b64875fd55
commit
c65dfb85d2
1 changed files with 28 additions and 29 deletions
|
@ -1,5 +1,4 @@
|
||||||
from manimlib.animation.animation import Animation
|
from manimlib.animation.animation import Animation
|
||||||
from manimlib.animation.animation import DEFAULT_ANIMATION_LAG_RATIO
|
|
||||||
from manimlib.animation.transform import Transform
|
from manimlib.animation.transform import Transform
|
||||||
from manimlib.constants import ORIGIN
|
from manimlib.constants import ORIGIN
|
||||||
from manimlib.constants import DOWN
|
from manimlib.constants import DOWN
|
||||||
|
@ -10,48 +9,48 @@ from manimlib.utils.rate_functions import there_and_back
|
||||||
DEFAULT_FADE_LAG_RATIO = 0
|
DEFAULT_FADE_LAG_RATIO = 0
|
||||||
|
|
||||||
|
|
||||||
class FadeOut(Transform):
|
class Fade(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):
|
|
||||||
self.to_vect = to_vect
|
|
||||||
super().__init__(mobject, **kwargs)
|
|
||||||
|
|
||||||
def create_target(self):
|
|
||||||
result = self.mobject.copy()
|
|
||||||
result.set_opacity(0)
|
|
||||||
result.shift(self.to_vect)
|
|
||||||
return result
|
|
||||||
|
|
||||||
# def clean_up_from_scene(self, scene=None):
|
|
||||||
# super().clean_up_from_scene(scene)
|
|
||||||
# self.interpolate(0)
|
|
||||||
|
|
||||||
|
|
||||||
class FadeIn(Transform):
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, mobject, from_vect=ORIGIN, **kwargs):
|
def __init__(self, mobject, shift=ORIGIN, scale=1, **kwargs):
|
||||||
self.from_vect = from_vect
|
self.shift_vect = shift
|
||||||
|
self.scale_factor = scale
|
||||||
super().__init__(mobject, **kwargs)
|
super().__init__(mobject, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class FadeIn(Fade):
|
||||||
|
CONFIG = {
|
||||||
|
"lag_ratio": DEFAULT_FADE_LAG_RATIO,
|
||||||
|
}
|
||||||
|
|
||||||
def create_target(self):
|
def create_target(self):
|
||||||
return self.mobject
|
return self.mobject
|
||||||
|
|
||||||
def create_starting_mobject(self):
|
def create_starting_mobject(self):
|
||||||
start = super().create_starting_mobject()
|
start = super().create_starting_mobject()
|
||||||
start.set_opacity(0)
|
start.set_opacity(0)
|
||||||
start.shift(self.from_vect)
|
start.scale(1.0 / self.scale_factor)
|
||||||
|
start.shift(-self.shift_vect)
|
||||||
return start
|
return start
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
# Below will be deprecated
|
# Below will be deprecated
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ class FadeOutAndShiftDown(FadeOut):
|
||||||
|
|
||||||
class FadeInFromPoint(FadeIn):
|
class FadeInFromPoint(FadeIn):
|
||||||
def __init__(self, mobject, point, **kwargs):
|
def __init__(self, mobject, point, **kwargs):
|
||||||
super().__init__(mobject, point - mobject.get_center(), **kwargs)
|
super().__init__(mobject, shift=mobject.get_center() - point, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class FadeInFromLarge(FadeIn):
|
class FadeInFromLarge(FadeIn):
|
||||||
|
|
Loading…
Add table
Reference in a new issue