Application Programming Interface¶
Manim Slides’ API is very limited: it simply consists of two classes, Slide
and ThreeDSlide
, which are subclasses of Scene
and ThreeDScene
from Manim.
Therefore, we only document here the methods we think the end-user will ever use, not the methods used internally when rendering.
Slide¶
- class Slide(*args: Any, output_folder: Path = PosixPath('slides'), **kwargs: Any)[source]¶
Inherits from
Scene
and provide necessary tools for slides rendering.- Parameters:
args (Any)
output_folder (Path)
kwargs (Any)
- add_to_canvas(**objects: Mobject) None ¶
Add objects to the canvas, using key values as names.
- Parameters:
objects (Mobject) – A mapping between names and Mobjects.
- Return type:
None
Note
This method does not actually do anything in terms of animations. You must still call
self.add
or play some animation that introduces each Mobject for it to appear. The same applies when removing objects.
- property canvas: MutableMapping[str, Mobject]¶
Return the canvas associated to the current slide.
The canvas is a mapping between names and Mobjects, for objects that are assumed to stay in multiple slides.
For example, a section title or a slide number.
Examples¶
Example: CanvasExample ¶
from manim import * from manim_slides import Slide class CanvasExample(Slide): def update_canvas(self): self.counter += 1 old_slide_number = self.canvas["slide_number"] new_slide_number = Text(f"{self.counter}").move_to(old_slide_number) self.play(Transform(old_slide_number, new_slide_number)) def construct(self): title = Text("My Title").to_corner(UL) self.counter = 1 slide_number = Text("1").to_corner(DL) self.add_to_canvas(title=title, slide_number=slide_number) self.play(FadeIn(title), FadeIn(slide_number)) self.next_slide() circle = Circle(radius=2) dot = Dot() self.update_canvas() self.play(Create(circle)) self.play(MoveAlongPath(dot, circle)) self.next_slide() self.update_canvas() square = Square() self.wipe(self.mobjects_without_canvas, square) self.next_slide() self.update_canvas() self.play( Transform( self.canvas["title"], Text("New Title").to_corner(UL) ) ) self.next_slide() self.remove_from_canvas("title", "slide_number") self.wipe(self.mobjects_without_canvas, [])
- property canvas_mobjects: ValuesView[Mobject]¶
Return Mobjects contained in the canvas.
- property mobjects_without_canvas: Sequence[Mobject]¶
Return the list of objects contained in the scene, minus those present in the canvas.
- next_section(*args: Any, **kwargs: Any) None [source]¶
Alias to
next_slide()
.- Parameters:
args (Any) – Positional arguments to be passed to
next_slide()
.kwargs (Any) – Keyword arguments to be passed to
next_slide()
.
- Return type:
None
Attention
This method is only available when using
manim
API.
- next_slide(*args: Any, loop: bool = False, auto_next: bool = False, playback_rate: float = 1.0, reversed_playback_rate: float = 1.0, notes: str = '', dedent_notes: bool = True, **kwargs: Any) None [source]¶
Create a new slide with previous animations, and setup options for the next slide.
This usually means that the user will need to press some key before the next slide is played. By default, this is the right arrow key.
- Parameters:
args (Any) – Positional arguments to be passed to
Scene.next_section
, or ignored if manimlib API is used.loop (bool) – If set, next slide will be looping.
auto_next (bool) –
If set, next slide will play immediately play the next slide upon terminating.
Note that this is only supported by
manim-slides present
andmanim-slides convert --to=html
.playback_rate (float) –
Playback rate at which the video is played.
Note that this is only supported by
manim-slides present
.reversed_playback_rate (float) –
Playback rate at which the reversed video is played.
Note that this is only supported by
manim-slides present
.notes (str) –
Presenter notes, in Markdown format.
Note that PowerPoint does not support Markdown.
Note that this is only supported by
manim-slides present
andmanim-slides convert --to=html/pptx
.dedent_notes (bool) – If set, apply
textwrap.dedent()
to notes.kwargs (Any) – Keyword arguments to be passed to
Scene.next_section
, or ignored if manimlib API is used.
- Return type:
None
Note
Calls to
next_slide()
at the very beginning or at the end are not needed, since they are automatically added.Warning
When rendered with RevealJS, loops cannot be in the first nor the last slide.
See also
When using
manim
API, this method will also callScene.next_section
.Examples¶
The following contains 3 slides:
the first with nothing on it;
the second with “Hello World!” fading in;
and the last with the text fading out;
Example: NextSlideExample ¶
from manim import * from manim_slides import Slide class NextSlideExample(Slide): def construct(self): text = Text("Hello World!") self.play(FadeIn(text)) self.next_slide() self.play(FadeOut(text))
The following contains one slide that will loop endlessly.
Example: LoopExample ¶
from manim import * from manim_slides import Slide class LoopExample(Slide): def construct(self): dot = Dot(color=BLUE, radius=1) self.play(FadeIn(dot)) self.next_slide(loop=True) self.play(Indicate(dot, scale_factor=2)) self.next_slide() self.play(FadeOut(dot))
The following contains one slide that triggers the next slide upon terminating.
Example: AutoNextExample ¶
from manim import * from manim_slides import Slide class AutoNextExample(Slide): def construct(self): square = Square(color=RED, side_length=2) self.play(GrowFromCenter(square)) self.next_slide(auto_next=True) self.play(Wiggle(square)) self.next_slide() self.wipe(square)
The following contains speaker notes. On the webbrowser, the speaker view can be triggered by pressing S.
Example: SpeakerNotesExample ¶
from manim import * from manim_slides import Slide class SpeakerNotesExample(Slide): def construct(self): self.next_slide(notes="Some introduction") square = Square(color=GREEN, side_length=2) self.play(GrowFromCenter(square)) self.next_slide(notes="We now rotate the slide") self.play(Rotate(square, PI / 2)) self.next_slide(notes="Bye bye") self.zoom(square)
- remove_from_canvas(*names: str) None ¶
Remove objects from the canvas.
- Parameters:
names (str)
- Return type:
None
- property wait_time_between_slides: float¶
Return the wait duration (in seconds) added between two slides.
By default, this value is set to 0.
Setting this value to something bigger than 0 will result in a
self.wait
animation called at the end of every slide.Note
This is useful because animations are usually only terminated when a new animation is played. You can observe the small difference in the examples below: the circle is not fully complete in the first slide of the first example, but well in the second example.
Examples¶
Example: WithoutWaitExample ¶
from manim import * from manim_slides import Slide class WithoutWaitExample(Slide): def construct(self): circle = Circle(radius=2) arrow = Arrow().next_to(circle, RIGHT).scale(-1) text = Text("Small\ngap").next_to(arrow, RIGHT) self.play(Create(arrow), FadeIn(text)) self.play(Create(circle)) self.next_slide() self.play(FadeOut(circle))
Example: WithWaitExample ¶
from manim import * from manim_slides import Slide class WithWaitExample(Slide): def construct(self): self.wait_time_between_slides = 0.1 # A small value > 1 / FPS circle = Circle(radius=2) arrow = Arrow().next_to(circle, RIGHT).scale(-1) text = Text("No more\ngap").next_to(arrow, RIGHT) self.play(Create(arrow), FadeIn(text)) self.play(Create(circle)) self.next_slide() self.play(FadeOut(circle))
- wipe(*args: Any, direction: np.ndarray = array([-1., 0., 0.]), return_animation: bool = False, **kwargs: Any) Wipe | None ¶
Play a wipe animation that will shift all the current objects outside of the current scene’s scope, and all the future objects inside.
- Parameters:
args (Any) – Positional arguments passed to
Wipe
.direction (np.ndarray) – The wipe direction, that will be scaled by the scene size.
return_animation (bool) – If set, return the animation instead of playing it. This is useful to combine multiple animations with this one.
kwargs (Any) – Keyword arguments passed to
Wipe
.
- Return type:
Wipe | None
Examples¶
Example: WipeExample ¶
from manim import * from manim_slides import Slide 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) beautiful = Text("Beautiful, no?") self.play(FadeIn(circle)) self.next_slide() self.wipe(circle, Group(square, text)) self.next_slide() self.wipe(Group(square, text), beautiful, direction=UP) self.next_slide() anim = self.wipe( beautiful, circle, direction=DOWN + RIGHT, return_animation=True ) self.play(anim)
- zoom(*args: Any, return_animation: bool = False, **kwargs: Any) Zoom | None ¶
Play 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.
- Parameters:
- Return type:
Zoom | None
Examples¶
Example: 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.zoom(circle, square) self.next_slide() anim = self.zoom( square, circle, out=True, scale=10.0, return_animation=True ) self.play(anim)
3D Slide¶
- class ThreeDSlide(*args: Any, output_folder: Path = PosixPath('slides'), **kwargs: Any)[source]¶
Inherits from
Slide
andThreeDScene
and provide necessary tools for slides rendering.Examples¶
Example: ThreeDExample ¶
from manim import * from manim_slides import ThreeDSlide class ThreeDExample(ThreeDSlide): def construct(self): title = Text("A 2D Text") self.play(FadeIn(title)) self.next_slide() sphere = Sphere([0, 0, -3]) self.move_camera(phi=PI/3, theta=-PI/4, distance=7) self.play( GrowFromCenter(sphere), Transform(title, Text("A 3D Text")) ) self.next_slide() bye = Text("Bye!") self.next_slide(loop=True) self.wipe( self.mobjects_without_canvas, [bye], direction=UP ) self.wait(.5) self.wipe( self.mobjects_without_canvas, [title, sphere], direction=DOWN ) self.wait(.5) self.next_slide() self.play(*[FadeOut(mobject) for mobject in self.mobjects])
- Parameters:
args (Any)
output_folder (Path)
kwargs (Any)
Animations¶
Additional animations for Manim objects.
Like with Manim, animations are classes that must be put inside a
Scene.play
call.
For each of the provided classes, there exists a method variant
that directly calls self.play(Animation(...))
, see
Slide
.
- class Wipe(mobject=None, *args, use_override=True, **kwargs)[source]¶
Creates a wipe animation that will shift all the current objects and future objects by a given value.
- Parameters:
current (Sequence[Mobject] | None) – A sequence of mobjects to remove from the scene.
future (Sequence[Mobject] | None) – A sequence of mobjects to add to the scene.
shift (ndarray) – The shift vector, used for both fading in and out.
fade_in_kwargs (Mapping[str, Any] | None) – Keyword arguments passed to
FadeIn
.fade_out_kwargs (Mapping[str, Any] | None) – Keyword arguments passed to
FadeOut
.kwargs (Any) – Keyword arguments passed to
AnimationGroup
.
Examples¶
Example: WipeClassExample ¶
from manim import * from manim_slides import Slide from manim_slides.slide.animation import Wipe class WipeClassExample(Slide): def construct(self): circle = Circle(radius=3, color=BLUE) square = Square() self.play(FadeIn(circle)) self.next_slide() self.play(Wipe(circle, square, shift=3 * LEFT))
- class Zoom(mobject=None, *args, use_override=True, **kwargs)[source]¶
Creates 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.
- Parameters:
current (Sequence[Mobject] | None) – A sequence of mobjects to remove from the scene.
future (Sequence[Mobject] | None) – A sequence of mobjects to add to the scene.
scale (float) – How much the objects are scaled (up or down).
out (bool) – If set, the objects fade in the opposite direction.
fade_in_kwargs (Mapping[str, Any] | None) – Keyword arguments passed to
FadeIn
.fade_out_kwargs (Mapping[str, Any] | None) – Keyword arguments passed to
FadeOut
.kwargs (Any) – Keyword arguments passed to
AnimationGroup
.
Examples¶
Example: ZoomClassExample ¶
from manim import * from manim_slides import Slide from manim_slides.slide.animation import Zoom class ZoomClassExample(Slide): def construct(self): circles = [Circle(radius=i) for i in range(1, 4)] self.play(FadeIn(circles[0])) self.next_slide() for i in range(2): self.play(Zoom(circles[i], circles[i+1])) self.next_slide()