mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-06-27 18:26:53 +08:00
feat(lib): add wip transition (#215)
This commit is contained in:
@ -5,6 +5,9 @@ from importlib.util import find_spec
|
|||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
# Constants
|
||||||
|
"FFMPEG_BIN",
|
||||||
|
"LEFT",
|
||||||
"MANIM",
|
"MANIM",
|
||||||
"MANIM_PACKAGE_NAME",
|
"MANIM_PACKAGE_NAME",
|
||||||
"MANIM_AVAILABLE",
|
"MANIM_AVAILABLE",
|
||||||
@ -13,11 +16,14 @@ __all__ = [
|
|||||||
"MANIMGL_PACKAGE_NAME",
|
"MANIMGL_PACKAGE_NAME",
|
||||||
"MANIMGL_AVAILABLE",
|
"MANIMGL_AVAILABLE",
|
||||||
"MANIMGL_IMPORTED",
|
"MANIMGL_IMPORTED",
|
||||||
"logger",
|
# Classes
|
||||||
|
"AnimationGroup",
|
||||||
|
"Mobject",
|
||||||
"Scene",
|
"Scene",
|
||||||
"ThreeDScene",
|
"ThreeDScene",
|
||||||
|
# Objects
|
||||||
|
"logger",
|
||||||
"config",
|
"config",
|
||||||
"FFMPEG_BIN",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -67,13 +73,21 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
if MANIMGL:
|
if MANIMGL:
|
||||||
from manimlib import Scene, ThreeDScene, config
|
from manimlib import LEFT, AnimationGroup, 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
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with suppress_stdout(): # Avoids printing "Manim Community v..."
|
with suppress_stdout(): # Avoids printing "Manim Community v..."
|
||||||
from manim import Scene, ThreeDScene, config, logger
|
from manim import (
|
||||||
|
LEFT,
|
||||||
|
AnimationGroup,
|
||||||
|
Mobject,
|
||||||
|
Scene,
|
||||||
|
ThreeDScene,
|
||||||
|
config,
|
||||||
|
logger,
|
||||||
|
)
|
||||||
|
|
||||||
try: # For manim<v0.16.0.post0
|
try: # For manim<v0.16.0.post0
|
||||||
from manim.constants import FFMPEG_BIN
|
from manim.constants import FFMPEG_BIN
|
||||||
|
@ -2,14 +2,25 @@ import os
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import Any, List, Optional, Tuple
|
from typing import Any, List, Optional, Sequence, Tuple
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from .config import PresentationConfig, SlideConfig, SlideType
|
from .config import PresentationConfig, SlideConfig, SlideType
|
||||||
from .defaults import FOLDER_PATH
|
from .defaults import FOLDER_PATH
|
||||||
from .manim import FFMPEG_BIN, MANIMGL, Scene, ThreeDScene, config, logger
|
from .manim import (
|
||||||
|
FFMPEG_BIN,
|
||||||
|
LEFT,
|
||||||
|
MANIMGL,
|
||||||
|
AnimationGroup,
|
||||||
|
Mobject,
|
||||||
|
Scene,
|
||||||
|
ThreeDScene,
|
||||||
|
config,
|
||||||
|
logger,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def reverse_video_file(src: str, dst: str) -> None:
|
def reverse_video_file(src: str, dst: str) -> None:
|
||||||
@ -54,6 +65,22 @@ class Slide(Scene): # type:ignore
|
|||||||
self.__loop_start_animation: Optional[int] = None
|
self.__loop_start_animation: Optional[int] = None
|
||||||
self.__pause_start_animation = 0
|
self.__pause_start_animation = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __frame_height(self) -> float:
|
||||||
|
"""Returns the scene's frame height."""
|
||||||
|
if MANIMGL:
|
||||||
|
return self.frame_height # type: ignore
|
||||||
|
else:
|
||||||
|
return config["frame_height"] # type: ignore
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __frame_width(self) -> float:
|
||||||
|
"""Returns the scene's frame width."""
|
||||||
|
if MANIMGL:
|
||||||
|
return self.frame_width # type: ignore
|
||||||
|
else:
|
||||||
|
return config["frame_width"] # type: ignore
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __background_color(self) -> str:
|
def __background_color(self) -> str:
|
||||||
"""Returns the scene's background color."""
|
"""Returns the scene's background color."""
|
||||||
@ -357,6 +384,50 @@ class Slide(Scene): # type:ignore
|
|||||||
|
|
||||||
self.__save_slides()
|
self.__save_slides()
|
||||||
|
|
||||||
|
def wipe(
|
||||||
|
self,
|
||||||
|
current: Sequence[Mobject] = [],
|
||||||
|
future: Sequence[Mobject] = [],
|
||||||
|
direction: np.ndarray = LEFT,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> AnimationGroup:
|
||||||
|
"""
|
||||||
|
Returns a wipe animation that will shift all the current objects outside
|
||||||
|
of the current scene's scope, and all the future objects inside.
|
||||||
|
|
||||||
|
:param current: A sequence of mobjects to remove from the scene.
|
||||||
|
:param future: A sequence of mobjects to add to the scene.
|
||||||
|
:direction: The wipe direction.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
class WipeExample(Slide):
|
||||||
|
def construct(self):
|
||||||
|
circle = Circle(radius=3, color=BLUE)
|
||||||
|
square = Square()
|
||||||
|
text = Text("This is a wipe example").next_to(square, DOWN)
|
||||||
|
|
||||||
|
self.play(Create(circle))
|
||||||
|
self.next_slide()
|
||||||
|
|
||||||
|
self.play(self.wipe(circle, Group(square, text)))
|
||||||
|
"""
|
||||||
|
shift_amount = np.asarray(direction) * np.array(
|
||||||
|
[self.__frame_width, self.__frame_height, 0.0]
|
||||||
|
)
|
||||||
|
|
||||||
|
for mobject in future:
|
||||||
|
mobject.shift(-shift_amount)
|
||||||
|
|
||||||
|
animations = [
|
||||||
|
mobject.animate.shift(shift_amount) for mobject in [*current, *future]
|
||||||
|
]
|
||||||
|
|
||||||
|
return AnimationGroup(*animations, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
|
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user