mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Created fading.py and growing.py to help break up animation.creation.py
This commit is contained in:
parent
691d5b7657
commit
88b35c45b8
12 changed files with 177 additions and 180 deletions
|
@ -19,6 +19,8 @@ from manimlib.constants import *
|
|||
from manimlib.animation.animation import *
|
||||
from manimlib.animation.composition import *
|
||||
from manimlib.animation.creation import *
|
||||
from manimlib.animation.fading import *
|
||||
from manimlib.animation.growing import *
|
||||
from manimlib.animation.indication import *
|
||||
from manimlib.animation.movement import *
|
||||
from manimlib.animation.numbers import *
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.animation.composition import Succession
|
||||
from manimlib.animation.composition import LaggedStart
|
||||
from manimlib.constants import *
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.utils.bezier import interpolate
|
||||
from manimlib.utils.bezier import integer_interpolate
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.paths import counterclockwise_path
|
||||
from manimlib.utils.rate_functions import linear
|
||||
from manimlib.utils.rate_functions import double_smooth
|
||||
from manimlib.utils.rate_functions import smooth
|
||||
|
@ -129,168 +120,10 @@ class Write(DrawBorderThenFill):
|
|||
|
||||
class ShowIncreasingSubsets(Animation):
|
||||
def __init__(self, group, **kwargs):
|
||||
self.all_submobs = group.submobjects
|
||||
self.all_submobs = list(group.submobjects)
|
||||
Animation.__init__(self, group, **kwargs)
|
||||
|
||||
def interpolate_mobject(self, alpha):
|
||||
n_submobs = len(self.all_submobs)
|
||||
index = int(alpha * n_submobs)
|
||||
self.mobject.submobjects = self.all_submobs[:index]
|
||||
|
||||
# Fading
|
||||
|
||||
|
||||
class FadeOut(Transform):
|
||||
CONFIG = {
|
||||
"remover": True,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
target.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
def clean_up_from_scene(self, scene=None):
|
||||
Transform.clean_up_from_scene(self, scene)
|
||||
self.interpolate(0)
|
||||
|
||||
|
||||
class FadeIn(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
self.starting_mobject.fade(1)
|
||||
if isinstance(self.starting_mobject, VMobject):
|
||||
self.starting_mobject.set_stroke(width=0)
|
||||
self.starting_mobject.set_fill(opacity=0)
|
||||
|
||||
|
||||
class FadeInAndShiftFromDirection(Transform):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
mobject.shift(direction)
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class FadeInFrom(FadeInAndShiftFromDirection):
|
||||
"""
|
||||
Alternate name for FadeInAndShiftFromDirection
|
||||
"""
|
||||
|
||||
|
||||
class FadeInFromDown(FadeInAndShiftFromDirection):
|
||||
"""
|
||||
Essential a more convenient form of FadeInAndShiftFromDirection
|
||||
"""
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
|
||||
class FadeOutAndShift(FadeOut):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
FadeOut.__init__(self, mobject, **kwargs)
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
self.target_mobject.shift(direction)
|
||||
|
||||
|
||||
class FadeOutAndShiftDown(FadeOutAndShift):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
|
||||
class FadeInFromLarge(Transform):
|
||||
def __init__(self, mobject, scale_factor=2, **kwargs):
|
||||
target = mobject.copy()
|
||||
mobject.scale(scale_factor)
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class VFadeIn(Animation):
|
||||
"""
|
||||
VFadeIn and VFadeOut only work for VMobjects, but they can be applied
|
||||
to mobjects while they are being animated in some other way (e.g. shifting
|
||||
then) in a way that does not work with FadeIn and FadeOut
|
||||
"""
|
||||
|
||||
def interpolate_submobject(self, submobject, starting_submobject, alpha):
|
||||
submobject.set_stroke(
|
||||
opacity=interpolate(0, starting_submobject.get_stroke_opacity(), alpha)
|
||||
)
|
||||
submobject.set_fill(
|
||||
opacity=interpolate(0, starting_submobject.get_fill_opacity(), alpha)
|
||||
)
|
||||
|
||||
|
||||
class VFadeOut(VFadeIn):
|
||||
CONFIG = {
|
||||
"remover": True
|
||||
}
|
||||
|
||||
def interpolate_submobject(self, submobject, starting_submobject, alpha):
|
||||
VFadeIn.interpolate_submobject(
|
||||
self, submobject, starting_submobject, 1 - alpha
|
||||
)
|
||||
|
||||
|
||||
# Growing
|
||||
|
||||
|
||||
class GrowFromPoint(Transform):
|
||||
CONFIG = {
|
||||
"point_color": None,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, point, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
mobject.scale(0)
|
||||
mobject.move_to(point)
|
||||
if self.point_color:
|
||||
mobject.set_color(self.point_color)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class GrowFromCenter(GrowFromPoint):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
GrowFromPoint.__init__(self, mobject, mobject.get_center(), **kwargs)
|
||||
|
||||
|
||||
class GrowFromEdge(GrowFromPoint):
|
||||
def __init__(self, mobject, edge, **kwargs):
|
||||
GrowFromPoint.__init__(
|
||||
self, mobject, mobject.get_critical_point(edge), **kwargs
|
||||
)
|
||||
|
||||
|
||||
class GrowArrow(GrowFromPoint):
|
||||
def __init__(self, arrow, **kwargs):
|
||||
GrowFromPoint.__init__(self, arrow, arrow.get_start(), **kwargs)
|
||||
|
||||
|
||||
class SpinInFromNothing(GrowFromCenter):
|
||||
CONFIG = {
|
||||
"path_func": counterclockwise_path()
|
||||
}
|
||||
|
||||
|
||||
class ShrinkToCenter(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
Transform.__init__(
|
||||
self, mobject, mobject.get_point_mobject(), **kwargs
|
||||
)
|
||||
|
|
114
manimlib/animation/fading.py
Normal file
114
manimlib/animation/fading.py
Normal file
|
@ -0,0 +1,114 @@
|
|||
from manimlib.animation.animation import Animation
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.constants import *
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.utils.bezier import interpolate
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
|
||||
|
||||
class FadeOut(Transform):
|
||||
CONFIG = {
|
||||
"remover": True,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
target.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
def clean_up_from_scene(self, scene=None):
|
||||
Transform.clean_up_from_scene(self, scene)
|
||||
self.interpolate(0)
|
||||
|
||||
|
||||
class FadeIn(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
self.starting_mobject.fade(1)
|
||||
if isinstance(self.starting_mobject, VMobject):
|
||||
self.starting_mobject.set_stroke(width=0)
|
||||
self.starting_mobject.set_fill(opacity=0)
|
||||
|
||||
|
||||
class FadeInAndShiftFromDirection(Transform):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
mobject.shift(direction)
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class FadeInFrom(FadeInAndShiftFromDirection):
|
||||
"""
|
||||
Alternate name for FadeInAndShiftFromDirection
|
||||
"""
|
||||
|
||||
|
||||
class FadeInFromDown(FadeInAndShiftFromDirection):
|
||||
"""
|
||||
Essential a more convenient form of FadeInAndShiftFromDirection
|
||||
"""
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
|
||||
class FadeOutAndShift(FadeOut):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
FadeOut.__init__(self, mobject, **kwargs)
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
self.target_mobject.shift(direction)
|
||||
|
||||
|
||||
class FadeOutAndShiftDown(FadeOutAndShift):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
|
||||
class FadeInFromLarge(Transform):
|
||||
def __init__(self, mobject, scale_factor=2, **kwargs):
|
||||
target = mobject.copy()
|
||||
mobject.scale(scale_factor)
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class VFadeIn(Animation):
|
||||
"""
|
||||
VFadeIn and VFadeOut only work for VMobjects, but they can be applied
|
||||
to mobjects while they are being animated in some other way (e.g. shifting
|
||||
then) in a way that does not work with FadeIn and FadeOut
|
||||
"""
|
||||
|
||||
def interpolate_submobject(self, submobject, starting_submobject, alpha):
|
||||
submobject.set_stroke(
|
||||
opacity=interpolate(0, starting_submobject.get_stroke_opacity(), alpha)
|
||||
)
|
||||
submobject.set_fill(
|
||||
opacity=interpolate(0, starting_submobject.get_fill_opacity(), alpha)
|
||||
)
|
||||
|
||||
|
||||
class VFadeOut(VFadeIn):
|
||||
CONFIG = {
|
||||
"remover": True
|
||||
}
|
||||
|
||||
def interpolate_submobject(self, submobject, starting_submobject, alpha):
|
||||
VFadeIn.interpolate_submobject(
|
||||
self, submobject, starting_submobject, 1 - alpha
|
||||
)
|
48
manimlib/animation/growing.py
Normal file
48
manimlib/animation/growing.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from manimlib.animation.transform import Transform
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.paths import counterclockwise_path
|
||||
|
||||
|
||||
class GrowFromPoint(Transform):
|
||||
CONFIG = {
|
||||
"point_color": None,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, point, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
mobject.scale(0)
|
||||
mobject.move_to(point)
|
||||
if self.point_color:
|
||||
mobject.set_color(self.point_color)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class GrowFromCenter(GrowFromPoint):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
GrowFromPoint.__init__(self, mobject, mobject.get_center(), **kwargs)
|
||||
|
||||
|
||||
class GrowFromEdge(GrowFromPoint):
|
||||
def __init__(self, mobject, edge, **kwargs):
|
||||
GrowFromPoint.__init__(
|
||||
self, mobject, mobject.get_critical_point(edge), **kwargs
|
||||
)
|
||||
|
||||
|
||||
class GrowArrow(GrowFromPoint):
|
||||
def __init__(self, arrow, **kwargs):
|
||||
GrowFromPoint.__init__(self, arrow, arrow.get_start(), **kwargs)
|
||||
|
||||
|
||||
class SpinInFromNothing(GrowFromCenter):
|
||||
CONFIG = {
|
||||
"path_func": counterclockwise_path()
|
||||
}
|
||||
|
||||
|
||||
class ShrinkToCenter(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
Transform.__init__(
|
||||
self, mobject, mobject.get_point_mobject(), **kwargs
|
||||
)
|
|
@ -9,7 +9,7 @@ from manimlib.animation.composition import AnimationGroup
|
|||
from manimlib.animation.composition import Succession
|
||||
from manimlib.animation.creation import ShowCreation
|
||||
from manimlib.animation.creation import ShowPartial
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.animation.update import UpdateFromAlphaFunc
|
||||
from manimlib.mobject.mobject import Mobject
|
||||
|
|
|
@ -2,9 +2,9 @@ import random
|
|||
|
||||
from manimlib.animation.composition import OldLaggedStart
|
||||
from manimlib.animation.creation import DrawBorderThenFill
|
||||
from manimlib.animation.creation import FadeIn
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.creation import Write
|
||||
from manimlib.animation.fading import FadeIn
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.constants import *
|
||||
from manimlib.continual_animation.continual_animation import ContinualMovement
|
||||
from manimlib.for_3b1b_videos.pi_creature import Mortimer
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from manimlib.animation.animation import Animation
|
||||
from manimlib.animation.composition import AnimationGroup
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.animation.creation import ShowCreation
|
||||
from manimlib.animation.creation import Write
|
||||
from manimlib.animation.transform import ApplyMethod
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.composition import AnimationGroup
|
||||
from manimlib.animation.creation import FadeIn
|
||||
from manimlib.animation.creation import GrowFromCenter
|
||||
from manimlib.constants import *
|
||||
from manimlib.animation.fading import FadeIn
|
||||
from manimlib.animation.growing import GrowFromCenter
|
||||
from manimlib.mobject.svg.tex_mobject import TexMobject
|
||||
from manimlib.mobject.svg.tex_mobject import TextMobject
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from manimlib.animation.creation import FadeIn
|
||||
from manimlib.animation.creation import ShowCreation
|
||||
from manimlib.animation.fading import FadeIn
|
||||
from manimlib.animation.transform import MoveToTarget
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.constants import *
|
||||
|
|
|
@ -3,8 +3,8 @@ from traceback import *
|
|||
from scipy.spatial import ConvexHull
|
||||
|
||||
from manimlib.animation.composition import OldLaggedStart
|
||||
from manimlib.animation.creation import FadeIn
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.fading import FadeIn
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.constants import *
|
||||
from manimlib.continual_animation.continual_animation import ContinualAnimation
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.creation import ShowCreation
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.animation.transform import ApplyMethod
|
||||
from manimlib.animation.transform import Transform
|
||||
from manimlib.constants import *
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.animation.creation import FadeOut
|
||||
from manimlib.animation.creation import GrowArrow
|
||||
from manimlib.animation.creation import ShowCreation
|
||||
from manimlib.animation.creation import Write
|
||||
from manimlib.animation.fading import FadeOut
|
||||
from manimlib.animation.growing import GrowArrow
|
||||
from manimlib.animation.transform import ApplyFunction
|
||||
from manimlib.animation.transform import ApplyPointwiseFunction
|
||||
from manimlib.animation.transform import Transform
|
||||
|
|
Loading…
Add table
Reference in a new issue