mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
feat(lib): improve wipe animation (#217)
* feat(lib): improve wipe animation Improve wipe transition by using FadeIn and FadeOut. The also allows to support introducers and removers. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -18,6 +18,8 @@ __all__ = [
|
|||||||
"MANIMGL_IMPORTED",
|
"MANIMGL_IMPORTED",
|
||||||
# Classes
|
# Classes
|
||||||
"AnimationGroup",
|
"AnimationGroup",
|
||||||
|
"FadeIn",
|
||||||
|
"FadeOut",
|
||||||
"Mobject",
|
"Mobject",
|
||||||
"Scene",
|
"Scene",
|
||||||
"ThreeDScene",
|
"ThreeDScene",
|
||||||
@ -73,7 +75,16 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
if MANIMGL:
|
if MANIMGL:
|
||||||
from manimlib import LEFT, AnimationGroup, Mobject, Scene, ThreeDScene, config
|
from manimlib import (
|
||||||
|
LEFT,
|
||||||
|
AnimationGroup,
|
||||||
|
FadeIn,
|
||||||
|
FadeOut,
|
||||||
|
Mobject,
|
||||||
|
Scene,
|
||||||
|
ThreeDScene,
|
||||||
|
config,
|
||||||
|
)
|
||||||
from manimlib.constants import FFMPEG_BIN
|
from manimlib.constants import FFMPEG_BIN
|
||||||
from manimlib.logger import log as logger
|
from manimlib.logger import log as logger
|
||||||
|
|
||||||
@ -82,6 +93,8 @@ else:
|
|||||||
from manim import (
|
from manim import (
|
||||||
LEFT,
|
LEFT,
|
||||||
AnimationGroup,
|
AnimationGroup,
|
||||||
|
FadeIn,
|
||||||
|
FadeOut,
|
||||||
Mobject,
|
Mobject,
|
||||||
Scene,
|
Scene,
|
||||||
ThreeDScene,
|
ThreeDScene,
|
||||||
|
@ -2,7 +2,7 @@ import os
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import Any, List, Optional, Sequence, Tuple
|
from typing import Any, List, Mapping, Optional, Sequence, Tuple
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -15,6 +15,8 @@ from .manim import (
|
|||||||
LEFT,
|
LEFT,
|
||||||
MANIMGL,
|
MANIMGL,
|
||||||
AnimationGroup,
|
AnimationGroup,
|
||||||
|
FadeIn,
|
||||||
|
FadeOut,
|
||||||
Mobject,
|
Mobject,
|
||||||
Scene,
|
Scene,
|
||||||
ThreeDScene,
|
ThreeDScene,
|
||||||
@ -39,7 +41,7 @@ def reverse_video_file(src: str, dst: str) -> None:
|
|||||||
|
|
||||||
class Slide(Scene): # type:ignore
|
class Slide(Scene): # type:ignore
|
||||||
"""
|
"""
|
||||||
Inherits from :class:`manim.scene.scene.Scene` or :class:`manimlib.scene.scene.Scene` and provide necessary tools for slides rendering.
|
Inherits from :class:`Scene<manim.scene.scene.Scene>` and provide necessary tools for slides rendering.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -253,14 +255,14 @@ class Slide(Scene): # type:ignore
|
|||||||
|
|
||||||
class LoopExample(Slide):
|
class LoopExample(Slide):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
dot = Dot(color=BLUE)
|
dot = Dot(color=BLUE, radius=1)
|
||||||
|
|
||||||
self.play(FadeIn(dot))
|
self.play(FadeIn(dot))
|
||||||
self.next_slide()
|
self.next_slide()
|
||||||
|
|
||||||
self.start_loop()
|
self.start_loop()
|
||||||
|
|
||||||
self.play(Indicate(dot))
|
self.play(Indicate(dot, scale_factor=2))
|
||||||
|
|
||||||
self.end_loop()
|
self.end_loop()
|
||||||
|
|
||||||
@ -398,6 +400,8 @@ class Slide(Scene): # type:ignore
|
|||||||
current: Sequence[Mobject] = [],
|
current: Sequence[Mobject] = [],
|
||||||
future: Sequence[Mobject] = [],
|
future: Sequence[Mobject] = [],
|
||||||
direction: np.ndarray = LEFT,
|
direction: np.ndarray = LEFT,
|
||||||
|
fade_in_kwargs: Mapping[str, Any] = {},
|
||||||
|
fade_out_kwargs: Mapping[str, Any] = {},
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> AnimationGroup:
|
) -> AnimationGroup:
|
||||||
"""
|
"""
|
||||||
@ -406,7 +410,13 @@ class Slide(Scene): # type:ignore
|
|||||||
|
|
||||||
:param current: A sequence of mobjects to remove from the scene.
|
:param current: A sequence of mobjects to remove from the scene.
|
||||||
:param future: A sequence of mobjects to add to the scene.
|
:param future: A sequence of mobjects to add to the scene.
|
||||||
:direction: The wipe direction.
|
:param direction: The wipe direction.
|
||||||
|
:param fade_in_kwargs: Keyword arguments passed to
|
||||||
|
:class:`FadeIn<manim.animation.fading.FadeIn>`.
|
||||||
|
:param fade_out_kwargs: Keyword arguments passed to
|
||||||
|
:class:`FadeOut<manim.animation.fading.FadeOut>`.
|
||||||
|
:param kwargs: Keyword arguments passed to
|
||||||
|
:class:`AnimationGroup<manim.animation.composition.AnimationGroup>`.
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
@ -421,29 +431,37 @@ class Slide(Scene): # type:ignore
|
|||||||
circle = Circle(radius=3, color=BLUE)
|
circle = Circle(radius=3, color=BLUE)
|
||||||
square = Square()
|
square = Square()
|
||||||
text = Text("This is a wipe example").next_to(square, DOWN)
|
text = Text("This is a wipe example").next_to(square, DOWN)
|
||||||
|
beautiful = Text("Beautiful, no?")
|
||||||
|
|
||||||
self.play(Create(circle))
|
self.play(Create(circle))
|
||||||
self.next_slide()
|
self.next_slide()
|
||||||
|
|
||||||
self.play(self.wipe(circle, Group(square, text)))
|
self.play(self.wipe(circle, Group(square, text)))
|
||||||
|
self.next_slide()
|
||||||
|
|
||||||
|
self.play(self.wipe(Group(square, text), beautiful, direction=UP))
|
||||||
|
self.next_slide()
|
||||||
|
|
||||||
|
self.play(self.wipe(beautiful, circle, direction=DOWN + RIGHT))
|
||||||
"""
|
"""
|
||||||
shift_amount = np.asarray(direction) * np.array(
|
shift_amount = np.asarray(direction) * np.array(
|
||||||
[self.__frame_width, self.__frame_height, 0.0]
|
[self.__frame_width, self.__frame_height, 0.0]
|
||||||
)
|
)
|
||||||
|
|
||||||
for mobject in future:
|
animations = []
|
||||||
mobject.shift(-shift_amount)
|
|
||||||
|
|
||||||
animations = [
|
for mobject in future:
|
||||||
mobject.animate.shift(shift_amount) for mobject in [*current, *future]
|
animations.append(FadeIn(mobject, shift=shift_amount, **fade_in_kwargs))
|
||||||
]
|
|
||||||
|
for mobject in current:
|
||||||
|
animations.append(FadeOut(mobject, shift=shift_amount, **fade_out_kwargs))
|
||||||
|
|
||||||
return AnimationGroup(*animations, **kwargs)
|
return AnimationGroup(*animations, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
|
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
|
||||||
"""
|
"""
|
||||||
Inherits from :class:`Slide` and :class:`manim.scene.three_d_scene.ThreeDScene` or :class:`manimlib.scene.three_d_scene.ThreeDScene` and provide necessary tools for slides rendering.
|
Inherits from :class:`Slide` and :class:`ThreeDScene<manim.scene.three_d_scene.ThreeDScene>` and provide necessary tools for slides rendering.
|
||||||
|
|
||||||
.. note:: ManimGL does not need ThreeDScene for 3D rendering in recent versions, see `example.py`.
|
.. note:: ManimGL does not need ThreeDScene for 3D rendering in recent versions, see `example.py`.
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user