Fading¶
注意
旧版的各种 FadeInFrom
和 FadeOutFrom
等方法已经全部整合在 FadeIn
和 FadeOut
中,以参数的形式给出,使得类的使用更加简洁
FadeOut¶
-
class
manimlib.animation.fading.
FadeOut
(mobject: Mobject, shift: np.ndarray = array([0., 0., 0.]), scale: float = 1, **kwargs)¶ 淡出
scale
: 缩放倍数shift
: 移动向量
FadeOutExample¶
class FadeOutExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
self.add(mobjects)
self.wait(0.3)
self.play(
*[FadeOut(mob) for mob in mobjects]
)
self.wait()
FadeIn¶
-
class
manimlib.animation.fading.
FadeIn
(mobject: Mobject, shift: np.ndarray = array([0., 0., 0.]), scale: float = 1, **kwargs)¶ 淡入
scale
: 缩放倍数shift
: 移动向量
FadeInExample¶
class FadeInExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
self.play(
*[FadeIn(mob) for mob in mobjects]
)
self.wait()
FadeInFromExample¶
class FadeInFromExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
directions = [UP, LEFT, DOWN, RIGHT]
for direction in directions:
self.play(
*[FadeIn(mob, shift=direction) for mob in mobjects]
)
self.wait()
FadeOutAndShiftExample¶
class FadeOutAndShiftExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
directions = [UP, LEFT, DOWN, RIGHT]
self.add(mobjects)
self.wait(0.3)
for direction in directions:
self.play(
*[FadeOut(mob, shift=direction) for mob in mobjects]
)
self.wait()
FadeInFromLargeExample¶
class FadeInFromLargeExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
scale_factors = [0.3, 0.8, 1, 1.3, 1.8]
for scale_factor in scale_factors:
t_scale_factor = Text(
f"scale_factor = {scale_factor}", font="monospace")
t_scale_factor.to_edge(UP)
self.add(t_scale_factor)
self.play(
*[FadeIn(mob, scale=scale_factor) for mob in mobjects]
)
self.remove(t_scale_factor)
self.wait(0.3)
FadeInFromPoint¶
-
class
manimlib.animation.fading.
FadeInFromPoint
(mobject: Mobject, point: np.ndarray, **kwargs)¶ 从传入的一个坐标点淡入
scale
: 缩放倍数shift
: 移动向量
FadeInFromPointExample¶
class FadeInFromPointExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
self.wait()
self.play(
*[FadeInFromPoint(mob, UP*3) for mob in mobjects]
)
self.wait()
FadeOutToPoint¶
-
class
manimlib.animation.fading.
FadeOutToPoint
(mobject: Mobject, point: np.ndarray, **kwargs)¶ 淡出到指定的坐标点
scale
: 缩放倍数shift
: 移动向量
FadeOutToPointExample¶
class FadeOutToPointExample(Scene):
def construct(self):
mobjects = VGroup(
Circle(),
Circle(fill_opacity=1),
Text("Text").scale(2)
)
mobjects.scale(1.5)
mobjects.arrange(RIGHT, buff=2)
self.add(mobjects)
self.wait()
self.play(
*[FadeOutToPoint(mob, DOWN*3) for mob in mobjects]
)
self.wait()
FadeTransform¶
-
class
manimlib.animation.fading.
FadeTransform
(mobject: Mobject, target_mobject: Mobject, **kwargs)¶ 渐变
-
get_all_mobjects
() → list[Mobject]¶ Ordering must match the ording of arguments to interpolate_submobject
-
FadeTransformExample¶
class FadeTransformExample(Scene):
def construct(self):
m_a = Rectangle(width=6, height=2, color=BLUE, fill_opacity=1)
m_b = Text("Rectangle").scale(3)
self.add(m_a)
self.wait()
self.play(FadeTransform(m_a, m_b))
self.wait()
FadeTransformPieces¶
-
class
manimlib.animation.fading.
FadeTransformPieces
(mobject: Mobject, target_mobject: Mobject, **kwargs)¶ 子物件分别渐变为目标
FadeTransformPiecesExample¶
class FadeTransformPiecesExample(Scene):
def construct(self):
m_a = VGroup(*[
Circle(radius=0.4)
.move_to((np.random.random(3)-0.5) * 3)
for i in range(6)
])
m_b = Text("Circle").scale(3)
self.add(m_a)
self.wait()
self.play(FadeTransformPieces(m_a, m_b))
self.wait()
VFadeIn¶
-
class
manimlib.animation.fading.
VFadeIn
(mobject: manimlib.mobject.mobject.Mobject, **kwargs)¶ 淡入
VFadeOut¶
-
class
manimlib.animation.fading.
VFadeOut
(mobject: manimlib.mobject.mobject.Mobject, **kwargs)¶ 淡出
VFadeInThenOut¶
-
class
manimlib.animation.fading.
VFadeInThenOut
(mobject: manimlib.mobject.mobject.Mobject, **kwargs)¶ 淡入后淡出
Fade和VFade的区别:
FadeIn
的边从细变粗,从暗变亮。 VFadeIn
的边始终是正常粗细,从暗变亮。
FadeOut
和 VFadeOut
无区别