Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): improve wipe animation #217

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion manim_slides/manim.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"MANIMGL_IMPORTED",
# Classes
"AnimationGroup",
"FadeIn",
"FadeOut",
"Mobject",
"Scene",
"ThreeDScene",
Expand Down Expand Up @@ -73,7 +75,16 @@


if MANIMGL:
from manimlib import LEFT, AnimationGroup, Mobject, Scene, ThreeDScene, config
from manimlib import (

Check warning on line 78 in manim_slides/manim.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/manim.py#L78

Added line #L78 was not covered by tests
LEFT,
AnimationGroup,
FadeIn,
FadeOut,
Mobject,
Scene,
ThreeDScene,
config,
)
from manimlib.constants import FFMPEG_BIN
from manimlib.logger import log as logger

Expand All @@ -82,6 +93,8 @@
from manim import (
LEFT,
AnimationGroup,
FadeIn,
FadeOut,
Mobject,
Scene,
ThreeDScene,
Expand Down
38 changes: 28 additions & 10 deletions manim_slides/slide.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import platform
import shutil
import subprocess
from typing import Any, List, Optional, Sequence, Tuple
from typing import Any, List, Mapping, Optional, Sequence, Tuple

Check warning on line 5 in manim_slides/slide.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/slide.py#L5

Added line #L5 was not covered by tests
from warnings import warn

import numpy as np
Expand All @@ -15,6 +15,8 @@
LEFT,
MANIMGL,
AnimationGroup,
FadeIn,
FadeOut,
Mobject,
Scene,
ThreeDScene,
Expand All @@ -39,7 +41,7 @@

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__(
Expand Down Expand Up @@ -253,14 +255,14 @@

class LoopExample(Slide):
def construct(self):
dot = Dot(color=BLUE)
dot = Dot(color=BLUE, radius=1)

self.play(FadeIn(dot))
self.next_slide()

self.start_loop()

self.play(Indicate(dot))
self.play(Indicate(dot, scale_factor=2))

self.end_loop()

Expand Down Expand Up @@ -398,6 +400,8 @@
current: Sequence[Mobject] = [],
future: Sequence[Mobject] = [],
direction: np.ndarray = LEFT,
fade_in_kwargs: Mapping[str, Any] = {},
fade_out_kwargs: Mapping[str, Any] = {},
**kwargs: Any,
) -> AnimationGroup:
"""
Expand All @@ -406,7 +410,13 @@

: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.
: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
--------
Expand All @@ -421,29 +431,37 @@
circle = Circle(radius=3, color=BLUE)
square = Square()
text = Text("This is a wipe example").next_to(square, DOWN)
beautiful = Text("Beautiful, no?")

self.play(Create(circle))
self.next_slide()

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(
[self.__frame_width, self.__frame_height, 0.0]
)

animations = []

Check warning on line 451 in manim_slides/slide.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/slide.py#L451

Added line #L451 was not covered by tests

for mobject in future:
mobject.shift(-shift_amount)
animations.append(FadeIn(mobject, shift=shift_amount, **fade_in_kwargs))

Check warning on line 454 in manim_slides/slide.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/slide.py#L454

Added line #L454 was not covered by tests

animations = [
mobject.animate.shift(shift_amount) for mobject in [*current, *future]
]
for mobject in current:
animations.append(FadeOut(mobject, shift=shift_amount, **fade_out_kwargs))

Check warning on line 457 in manim_slides/slide.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/slide.py#L456-L457

Added lines #L456 - L457 were not covered by tests

return AnimationGroup(*animations, **kwargs)


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`.
"""
Expand Down
Loading