mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
feat(lib): add zoom animation (#230)
* feat(lib): add zoom animation * chore(lib): fix zoom animation
This commit is contained in:
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
@ -47,7 +47,7 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install libcairo2-dev libpango1.0-dev ffmpeg freeglut3-dev
|
||||
- name: Install local Python package
|
||||
run: poetry install --extras=manim --with docs
|
||||
run: poetry install --with docs
|
||||
- name: Restore cached media
|
||||
id: cache-media-restore
|
||||
uses: actions/cache/restore@v3
|
||||
|
@ -18,6 +18,7 @@ Therefore, we only document here the methods we think the end-user will ever use
|
||||
start_loop,
|
||||
wait_time_between_slides,
|
||||
wipe,
|
||||
zoom,
|
||||
|
||||
.. autoclass:: manim_slides.ThreeDSlide
|
||||
:members:
|
||||
|
@ -606,7 +606,7 @@ class Slide(Scene): # type:ignore
|
||||
text = Text("This is a wipe example").next_to(square, DOWN)
|
||||
beautiful = Text("Beautiful, no?")
|
||||
|
||||
self.play(Create(circle))
|
||||
self.play(FadeIn(circle))
|
||||
self.next_slide()
|
||||
|
||||
self.play(self.wipe(circle, Group(square, text)))
|
||||
@ -631,6 +631,69 @@ class Slide(Scene): # type:ignore
|
||||
|
||||
return AnimationGroup(*animations, **kwargs)
|
||||
|
||||
def zoom(
|
||||
self,
|
||||
current: Sequence[Mobject] = [],
|
||||
future: Sequence[Mobject] = [],
|
||||
scale: float = 4.0,
|
||||
out: bool = False,
|
||||
fade_in_kwargs: Mapping[str, Any] = {},
|
||||
fade_out_kwargs: Mapping[str, Any] = {},
|
||||
**kwargs: Any,
|
||||
) -> AnimationGroup:
|
||||
"""
|
||||
Returns a zoom animation that will fade out all the current objects,
|
||||
and fade in all the future objects. Objects are faded in a direction
|
||||
that goes towards the camera.
|
||||
|
||||
:param current: A sequence of mobjects to remove from the scene.
|
||||
:param future: A sequence of mobjects to add to the scene.
|
||||
:param scale: How much the objects are scaled (up or down).
|
||||
:param out: If set, the objects fade in the opposite 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
|
||||
--------
|
||||
|
||||
.. manim-slides:: ZoomExample
|
||||
|
||||
from manim import *
|
||||
from manim_slides import Slide
|
||||
|
||||
class ZoomExample(Slide):
|
||||
def construct(self):
|
||||
circle = Circle(radius=3, color=BLUE)
|
||||
square = Square()
|
||||
|
||||
self.play(FadeIn(circle))
|
||||
self.next_slide()
|
||||
|
||||
self.play(self.zoom(circle, square))
|
||||
self.next_slide()
|
||||
|
||||
self.play(self.zoom(square, circle, out=True, scale=10.))
|
||||
"""
|
||||
scale_in = 1.0 / scale
|
||||
scale_out = scale
|
||||
|
||||
if out:
|
||||
scale_in, scale_out = scale_out, scale_in
|
||||
|
||||
animations = []
|
||||
|
||||
for mobject in future:
|
||||
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
|
||||
|
||||
for mobject in current:
|
||||
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
|
||||
|
||||
return AnimationGroup(*animations, **kwargs)
|
||||
|
||||
|
||||
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
|
||||
"""
|
||||
|
4203
poetry.lock
generated
4203
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,7 @@ version = "4.14.0"
|
||||
click = "^8.1.3"
|
||||
click-default-group = "^1.2.2"
|
||||
lxml = "^4.9.2"
|
||||
manim = {version = "^0.17.0", optional = true}
|
||||
manim = {version = "^0.17.3", optional = true}
|
||||
manimgl = {version = "^1.6.1", optional = true}
|
||||
numpy = "^1.19"
|
||||
opencv-python = "^4.6.0.66"
|
||||
@ -78,7 +78,7 @@ ruff = "^0.0.219"
|
||||
|
||||
[tool.poetry.group.docs.dependencies]
|
||||
furo = "^2023.5.20"
|
||||
manim = "^0.17.0"
|
||||
manim = "^0.17.3"
|
||||
myst-parser = "^2.0.0"
|
||||
sphinx = "^7.0.1"
|
||||
sphinx-click = "^4.4.0"
|
||||
|
Reference in New Issue
Block a user