Skip to content

Commit 9aa715a

Browse files
feat(cli): add convert option to generate html presentations (#66)
* wip(cli): convert slides to html using RevealJS * wip: convert - almost fully working * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: remove unused file * fix: add last slides in now performed during rendering * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(ci): testing ConvertExample too * fix: ManimGL does not consider wait as an animation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a373bdb commit 9aa715a

File tree

12 files changed

+821
-74
lines changed

12 files changed

+821
-74
lines changed

.github/workflows/pages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
run: pip install manim sphinx sphinx_click furo
4343
- name: Install local Python package
4444
run: pip install -e .
45+
- name: Build animation and convert it into HTML slides
46+
run: |
47+
manim example.py ConvertExample
48+
manim-slides convert ConvertExample docs/source/_static/slides.html -cembedded -ccontrols=true
4549
- name: Build docs
4650
run: cd docs && make html
4751
- name: Upload artifact

.github/workflows/test_examples.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ jobs:
8989
run: pip3 install -e .
9090
- name: Build slides with manim
9191
if: matrix.manim == 'manim'
92-
run: python -m manim -ql example.py Example ThreeDExample
92+
run: python -m manim -ql example.py Example ThreeDExample ConvertExample
9393
- name: Build slides with manimgl on Ubuntu
9494
if: matrix.manim == 'manimgl' && matrix.os == 'ubuntu-latest'
95-
run: xvfb-run -a -s "-screen 0 1400x900x24" manim-render -l example.py Example ThreeDExample
95+
run: xvfb-run -a -s "-screen 0 1400x900x24" manim-render -l example.py Example ThreeDExample ConvertExample
9696
- name: Build slides with manimgl on MacOS or Windows
9797
if: matrix.manim == 'manimgl' && (matrix.os == 'macos-latest' || matrix.os == 'windows-latest')
98-
run: manimgl -l example.py Example ThreeDExample
98+
run: manimgl -l example.py Example ThreeDExample ConvertExample
9999
- name: Test slides on Ubuntu
100100
if: matrix.os == 'ubuntu-latest'
101-
run: xvfb-run -a -s "-screen 0 1400x900x24" manim-slides Example ThreeDExample --skip-all
101+
run: xvfb-run -a -s "-screen 0 1400x900x24" manim-slides Example ThreeDExample ConvertExample --skip-all
102102
- name: Test slides on MacOS or Windows
103103
if: matrix.os == 'macos-latest' || matrix.os == 'windows-latest'
104-
run: manim-slides Example ThreeDExample --skip-all
104+
run: manim-slides Example ThreeDExample ConvertExample --skip-all

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ videos/
1919
images/
2020

2121
docs/build/
22+
23+
docs/source/_static/slides_assets/
24+
25+
docs/source/_static/slides.html

docs/source/index.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
contain the root `toctree` directive.
55
66
.. image:: _static/logo.png
7-
:width: 600
7+
:width: 600px
88
:align: center
99
:alt: Manim Slide logo
1010

1111
Welcome to Manim Slide's CLI documentation!
1212
===========================================
1313

14+
15+
.. raw:: html
16+
17+
<!-- From: https://faq.dailymotion.com/hc/en-us/articles/360022841393-How-to-preserve-the-player-aspect-ratio-on-a-responsive-page -->
18+
19+
<div style="position:relative;padding-bottom:56.25%;"> <iframe style="width:100%;height:100%;position:absolute;left:0px;top:0px;" frameborder="0" width="100%" height="100%" allowfullscreen allow="autoplay" src="_static/slides.html"></iframe></div>
20+
21+
1422
This page contains an exhaustive list of all the commands available with `manim-slides`.
1523

1624
If you need help installing or using Manim Slide, please refer to the `GitHub README <https://github.com/jeertmans/manim-slides>`_.

example.py

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,219 @@ def construct(self):
4242
self.play(dot.animate.move_to(ORIGIN))
4343

4444

45+
class ConvertExample(Slide):
46+
def tinywait(self):
47+
self.wait(0.1)
48+
49+
def construct(self):
50+
51+
title = VGroup(
52+
Text("From Manim animations", t2c={"From": BLUE}),
53+
Text("to slides presentation", t2c={"to": BLUE}),
54+
Text("with Manim Slides", t2w={"[-12:]": BOLD}, t2c={"[-13:]": YELLOW}),
55+
).arrange(DOWN)
56+
57+
step_1 = Text("1. In your scenes file, import Manim Slides")
58+
step_2 = Text("2. Replace Scene with Slide")
59+
step_3 = Text("3. In construct, add pauses where you need")
60+
step_4 = Text("4. You can also create loops")
61+
step_5 = Text("5. Render you scene with Manim")
62+
step_6 = Text("6. Open your presentation with Manim Slides")
63+
64+
for step in [step_1, step_2, step_3, step_4, step_5, step_6]:
65+
step.scale(0.5).to_corner(UL)
66+
67+
step = step_1
68+
69+
self.play(FadeIn(title))
70+
71+
self.pause()
72+
73+
code = Code(
74+
code="""from manim import *
75+
76+
77+
class Example(Scene):
78+
def construct(self):
79+
dot = Dot()
80+
self.add(dot)
81+
82+
self.play(Indicate(dot, scale_factor=2))
83+
84+
square = Square()
85+
self.play(Transform(dot, square))
86+
87+
self.play(Rotate(square, angle=PI/2))
88+
""",
89+
language="python",
90+
)
91+
92+
code_step_1 = Code(
93+
code="""from manim import *
94+
from manim_slides import Slide
95+
96+
class Example(Scene):
97+
def construct(self):
98+
dot = Dot()
99+
self.add(dot)
100+
101+
self.play(Indicate(dot, scale_factor=2))
102+
103+
square = Square()
104+
self.play(Transform(dot, square))
105+
106+
self.play(Rotate(square, angle=PI/2))
107+
""",
108+
language="python",
109+
)
110+
111+
code_step_2 = Code(
112+
code="""from manim import *
113+
from manim_slides import Slide
114+
115+
class Example(Slide):
116+
def construct(self):
117+
dot = Dot()
118+
self.add(dot)
119+
120+
self.play(Indicate(dot, scale_factor=2))
121+
122+
square = Square()
123+
self.play(Transform(dot, square))
124+
125+
self.play(Rotate(square, angle=PI/2))
126+
""",
127+
language="python",
128+
)
129+
130+
code_step_3 = Code(
131+
code="""from manim import *
132+
from manim_slides import Slide
133+
134+
class Example(Slide):
135+
def construct(self):
136+
dot = Dot()
137+
self.add(dot)
138+
139+
self.play(Indicate(dot, scale_factor=2))
140+
self.pause()
141+
square = Square()
142+
self.play(Transform(dot, square))
143+
self.pause()
144+
self.play(Rotate(square, angle=PI/2))
145+
""",
146+
language="python",
147+
)
148+
149+
code_step_4 = Code(
150+
code="""from manim import *
151+
from manim_slides import Slide
152+
153+
class Example(Slide):
154+
def construct(self):
155+
dot = Dot()
156+
self.add(dot)
157+
self.start_loop()
158+
self.play(Indicate(dot, scale_factor=2))
159+
self.end_loop()
160+
square = Square()
161+
self.play(Transform(dot, square))
162+
self.pause()
163+
self.play(Rotate(square, angle=PI/2))
164+
""",
165+
language="python",
166+
)
167+
168+
code_step_5 = Code(
169+
code="manim example.py Example",
170+
language="console",
171+
)
172+
173+
code_step_6 = Code(
174+
code="manim-slides Example",
175+
language="console",
176+
)
177+
178+
or_text = Text("or generate HTML presentation").scale(0.5)
179+
180+
code_step_7 = Code(
181+
code="manim-slides convert Example slides.html --open",
182+
language="console",
183+
).shift(DOWN)
184+
185+
self.clear()
186+
187+
self.play(FadeIn(code))
188+
self.tinywait()
189+
self.pause()
190+
191+
self.play(FadeIn(step, shift=RIGHT))
192+
self.play(Transform(code, code_step_1))
193+
self.tinywait()
194+
self.pause()
195+
196+
self.play(Transform(step, step_2))
197+
self.play(Transform(code, code_step_2))
198+
self.tinywait()
199+
self.pause()
200+
201+
self.play(Transform(step, step_3))
202+
self.play(Transform(code, code_step_3))
203+
self.tinywait()
204+
self.pause()
205+
206+
self.play(Transform(step, step_4))
207+
self.play(Transform(code, code_step_4))
208+
self.tinywait()
209+
self.pause()
210+
211+
self.play(Transform(step, step_5))
212+
self.play(Transform(code, code_step_5))
213+
self.tinywait()
214+
self.pause()
215+
216+
self.play(Transform(step, step_6))
217+
self.play(Transform(code, code_step_6))
218+
self.play(code.animate.shift(UP), FadeIn(code_step_7), FadeIn(or_text))
219+
self.tinywait()
220+
self.pause()
221+
222+
watch_text = Text("Watch result on next slides!").shift(2 * DOWN).scale(0.5)
223+
224+
self.start_loop()
225+
self.play(FadeIn(watch_text))
226+
self.play(FadeOut(watch_text))
227+
self.end_loop()
228+
self.clear()
229+
230+
dot = Dot()
231+
self.add(dot)
232+
self.start_loop()
233+
self.play(Indicate(dot, scale_factor=2))
234+
self.end_loop()
235+
square = Square()
236+
self.play(Transform(dot, square))
237+
self.remove(dot)
238+
self.add(square)
239+
self.tinywait()
240+
self.pause()
241+
self.play(Rotate(square, angle=PI / 4))
242+
self.tinywait()
243+
self.pause()
244+
245+
learn_more_text = (
246+
VGroup(
247+
Text("Learn more about Manim Slides:"),
248+
Text("https://github.com/jeertmans/manim-slides", color=YELLOW),
249+
)
250+
.arrange(DOWN)
251+
.scale(0.75)
252+
)
253+
254+
self.play(Transform(square, learn_more_text))
255+
self.tinywait()
256+
257+
45258
# For ThreeDExample, things are different
46259

47260
if not MANIMGL:

manim_slides/commons.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44
from click import Context, Parameter
55

6-
from .defaults import CONFIG_PATH
6+
from .defaults import CONFIG_PATH, FOLDER_PATH
77
from .manim import logger
88

99

@@ -60,3 +60,15 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
6060
show_envvar=True,
6161
callback=callback,
6262
)(function)
63+
64+
65+
def folder_path_option(function: Callable) -> Callable:
66+
"""Wraps a function to add folder path option."""
67+
return click.option(
68+
"--folder",
69+
metavar="DIRECTORY",
70+
default=FOLDER_PATH,
71+
type=click.Path(exists=True, file_okay=False),
72+
help="Set slides folder.",
73+
show_default=True,
74+
)(function)

0 commit comments

Comments
 (0)