3.3 KiB
Examples
Contents of example.py
.
Do not forget to import Manim Slides and Manim or ManimGL:
from manim import *
from manim_slides import Slide, ThreeDSlide
or
from manimlib import *
from manim_slides import Slide, ThreeDSlide
Then, each presentation, named SCENE
, was generated with those two commands:
manim example.py SCENE # or manimgl example SCENE
manim-slides convert SCENE scene.html -ccontrols=true
where -ccontrols=true
indicates that we want to display the blue navigation arrows.
Basic Example
Basic example from quickstart.
.. literalinclude:: ../../../example.py
:language: python
:linenos:
:pyobject: BasicExample
3D Example
Example using 3D camera. As Manim and ManimGL handle 3D differently, definitions are slightly different.
With Manim
.. literalinclude:: ../../../example.py
:language: python
:linenos:
:dedent: 4
:start-after: [manim-3d]
:end-before: [manim-3d]
With ManimGL
.. literalinclude:: ../../../example.py
:language: python
:linenos:
:dedent: 4
:start-after: [manimgl-3d]
:end-before: [manimgl-3d]
Subclass Custom Scenes
For compatibility reasons, Manim Slides only provides subclasses for
Scene
and ThreeDScene
.
However, subclassing other scene classes is totally possible,
and very simple to do actually!
For example,
you can subclass the MovingCameraScene
class from manim
with the following code:
:linenos:
from manim import *
from manim_slides import Slide
class MovingCameraSlide(Slide, MovingCameraScene):
pass
And later use this class anywhere in your code:
:linenos:
class SubclassExample(MovingCameraSlide):
def construct(self):
eq1 = MathTex("x", "=", "1")
eq2 = MathTex("x", "=", "2")
self.play(Write(eq1))
self.next_slide()
self.play(
TransformMatchingTex(eq1, eq2),
self.camera.frame.animate.scale(0.5)
)
self.wait()
:::{note}
If you do not plan to reuse MovingCameraSlide
more than once, then you can
directly write the construct
method in the body of MovingCameraSlide
.
:::
Advanced Example
A more advanced example is ConvertExample
, which is used as demo slide and tutorial.
.. literalinclude:: ../../../example.py
:language: python
:linenos:
:pyobject: ConvertExample