Skip to content

The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.

Python

Document rendering, audio, and cameras

apoogdk61f7759e010f
diff --git a/docs/content/user-guide/camera-and-3d.md b/docs/content/user-guide/camera-and-3d.md
new file mode 100644
index 00000000..823ab7f6
--- /dev/null
+++ b/docs/content/user-guide/camera-and-3d.md
@@ -0,0 +1,79 @@
+# Camera and 3D
+
+The camera decides what the video shows. Its frame is a rectangle in the scene: the frame
+that [Positions](positions.md) measures. Move the frame, and the view moves with it.
+
+## Pan and zoom
+
+`self.camera.frame` is a mobject. Animate it as any other mobject:
+
+```python
+import manimgx as m
+
+
+class Zoom(m.Scene):
+ def construct(self) -> None:
+ circle = m.Circle(radius=3, color=m.BLUE)
+ tangent = m.Line(4 * m.LEFT, 4 * m.RIGHT, color=m.YELLOW)
+ tangent.shift(3 * m.UP)
+ self.add(circle, tangent)
+ frame = self.camera.frame
+ self.play(frame.animate.scale(0.25).move_to(3 * m.UP), run_time=2)
+ self.wait()
+ self.play(frame.animate.scale(4).move_to(m.ORIGIN), run_time=2)
+```
+
+- Move the frame to pan: `frame.animate.move_to(point)`.
+- Scale it to zoom: a frame half as large shows everything twice as large.
+
+## Three dimensions
+
+To make a scene in 3D, make it from `m.ThreeDScene`. Its camera looks at the frame from
+two angles:
+
+- `phi`, its angle from straight above: 0 looks straight down, as in a flat scene.
+- `theta`, its angle around the vertical axis.
+
+```python
+import manimgx as m
+import numpy as np
+
+
+class Hill(m.ThreeDScene):
+ def construct(self) -> None:
+ axes = m.ThreeDAxes(
+ x_range=[-3, 3],
+ y_range=[-3, 3],
+ z_range=[0, 2],
+ x_length=7,
+ y_length=7,
+ z_length=3,
+ )
+
+ def height(u: float, v: float) -> np.ndarray:
+ return axes.c2p(u, v, 2 * np.exp(-(u**2 + v**2) / 2))
+
+ hill = m.Surface(height, u_range=[-2.5, 2.5], v_range=[-2.5, 2.5])
+ title = m.Text("A hill", font_size=40)
+ title.to_corner(m.UL)
+ self.add_fixed_in_frame_mobjects(title)
+ self.add(axes, hill)
+ self.move_camera(phi=65 * m.DEGREES, theta=-45 * m.DEGREES, run_time=2)
+ self.begin_ambient_camera_rotation(rate=0.3)
+ self.wait(3)
+```
+
+- `self.set_camera_orientation(phi=..., theta=...)` turns the camera at once, and
+ `self.move_camera(...)` turns it in an animation.
+- `self.begin_ambient_camera_rotation(rate=0.3)` turns the camera around the scene, until
+ `self.stop_ambient_camera_rotation()`.
+- `self.add_fixed_in_frame_mobjects(title)` keeps a mobject still on the screen while the
+ camera moves: here, the title stays in its corner.
+
+Every mobject has three coordinates, so flat mobjects work in 3D too. The
+[reference][manimgx.mobjects.three_d] shows the mobjects made for 3D, such as
+spheres and cubes.
+
+## Next
+
+[Sound and voice](sound-and-voice.md) shows how to add sound and a voice to your video.
diff --git a/docs/content/user-guide/coming-from-manim-ce.md b/docs/content/user-guide/coming-from-manim-ce.md
new file mode 100644
index 00000000..abaddec0
--- /dev/null
+++ b/docs/content/user-guide/coming-from-manim-ce.md
@@ -0,0 +1,82 @@
+# Coming from Manim CE
+
+manimgx has the API of [Manim Community Edition](https://www.manim.community): its scenes,
+mobjects, animations and constants, with the same names and parameters. Most Manim CE code
+runs on manimgx after you replace `manim` with `manimgx`. But manimgx decides how that
+code behaves. This page shows where it is different.
+
+## Imports and rendering
+
+- Every name is in the package: `import manimgx as m`, then `m.Circle`, or
+ `from manimgx import *`. Manim CE's modules are not there: write
+ `from manimgx import polylabel`, not `from manimgx.utils.polylabel import polylabel`.
+- Render with `manimgx render scene.py MyScene`. Manim CE's quality flags (`-ql`, `-qh`,
+ …) become `-r` (`--resolution`) and `--fps`. `manimgx check` reports a scene's layout problems without a video. See
+ [Rendering and sharing](rendering.md).
+- You don't install LaTeX. `Tex` and `MathTex` convert their LaTeX to
+ [Typst](https://typst.app), which the engine sets. LaTeX packages and `\def` don't
+ convert.
+
+## The frame
+
+A wide video's frame is the same as in Manim CE: 8 units high, about 14.2 wide. A tall
+video's frame (9:16) is 8 units wide and about 14.2 high, where Manim CE's is 4.5 wide:
+in manimgx, the frame's short side is 8 units, unless you set `config.frame_height`. So
+a scene made for a wide video fits a tall one if it stays in the middle 8 × 8 square.
+
+## Time and animations
+
+- Each frame shows the scene at its own exact time, in plays and in waits, at every frame
+ rate. The video ends with a last frame at the scene's end.
+- Updaters get the exact time since their last call. They keep running while an
+ animation plays their mobject. Updaters that take `dt` run on a clock of their own, so
+ a simulation gives the same result at every frame rate.
+- `.animate` applies its calls when its animation starts. In a `Succession`, each
+ `.animate` starts where the one before it ended.
+- A rotation turns the mobject as one rigid piece, about one point.
+- Animations of one mobject that start at the same time combine: their movements add.
+
+See [Animations](animations.md) and [Updaters](updaters.md).
+
+## One name for each thing
+
+For most things that Manim CE names twice, manimgx keeps one name. The other still
+works, but your editor marks it deprecated and names the one to use:
+
+- `MovingCameraScene` is `Scene`: every scene's camera moves.
+- `ApplyMethod(square.scale, 2)`, `ScaleInPlace(square, 2)` and
+ `FadeToColor(square, m.RED)` are `.animate`: `square.animate.scale(2)`,
+ `square.animate.set_color(m.RED)`.
+- `arrange_submobjects` is `arrange`, `rotate_about_origin(angle)` is
+ `rotate(angle, about_point=m.ORIGIN)`, and `get_edge_center(m.UP)` is `get_top()`.
+- `PGroup` is `Group`, and the singular `add_foreground_mobject` is
+ `add_foreground_mobjects`.
+
+`VGroup` and `Group` are the same class too, and `c2p` is `coords_to_point`, but both
+names of these are everywhere in Manim code, so both stay. These docs use `VGroup` and
+`c2p`.
+
+## Types
+
+Every keyword argument has a type, and so do `.animate` chains. So a type checker such as
+[ty](https://docs.astral.sh/ty/) finds a name that manimgx doesn't have, or an argument
+of the wrong type, before you render. The [Quickstart](quickstart.md#2-set-up-your-editor) sets it up in your editor.
+
+## Sound, slides and voiceover
+
+manimgx does the work of manim-voiceover and manim-slides, without plugins:
+
+- [`add_sound`][manimgx.Scene.add_sound] puts a sound in the video. A
+ [`Sound`][manimgx.Sound] can also be a part of a play.
+- A voiceover is `self.say("The derivative of [x squared] is [two x].", anim1, anim2)`.
+ Each animation plays during its words in brackets, and the scene waits until the line
+ ends. This replaces `with self.voiceover(...) as tracker:`, bookmarks and
+ `run_time=tracker.duration`. Any text-to-speech service can be a voice.
+- [`next_section`][manimgx.Scene.next_section] starts a section of one video, not a
+ separate file. `manimgx present` shows the sections as slides. Use
+ `self.next_section()` instead of `self.next_slide()`, and `"presentation.loop"` instead
+ of `loop=True`. `notes=` works as before.
+- [`add_subcaption`][manimgx.Scene.add_subcaption] adds captions. `manimgx render` writes
+ them next to the video, as subtitles.
+
+See [Sound and voice](sound-and-voice.md) and [Rendering and sharing](rendering.md#slides).
diff --git a/docs/content/user-guide/rendering.md b/docs/content/user-guide/rendering.md
new file mode 100644
index 00000000..e6749ef5
--- /dev/null
+++ b/docs/content/user-guide/rendering.md
@@ -0,0 +1,183 @@
+# Rendering and sharing
+
+The `manimgx` command makes the video of a scene. It also plays the scene in a window,
+checks it for problems, and presents it as slides:
+
+| Command | What it does |
+| --- | --- |
+| `manimgx render scene.py` | Makes the video, an MP4 file. |
+| `manimgx preview scene.py` | Plays the scene in a window, and plays it again each time that you save. |
+| `manimgx check scene.py` | Finds problems that a viewer would see, such as text that the frame cuts off. |
+| `manimgx still scene.py` | Draws the picture at a moment, as a PNG file. |
+| `manimgx present scene.py` | Makes the video, and shows it as slides in your browser. |
+
+Each command writes its files next to the scene's file. If the file has several scenes,
+give the scene's name after the file: `manimgx render scene.py Intro`. The
+[command line reference](../reference/rendering/command-line.md) shows all the options.
+
+## Render
+
+```console
+$ manimgx render square_to_circle.py
+SquareToCircle.mp4 3.00 s, 1920x1080 at 60 fps, 0.4 MB (rendered in 0.7 s)
+storyboard: SquareToCircle.storyboard.png
+layout: no problems at the end of any of the 3 plays
+```
+
+The video is named after the scene. It is 1920 × 1080 pixels, at 60 frames each second,
+with the scene's sound. `-o` gives it a different name. For a quick draft, make it
+smaller: `-r 1280x720 --fps 30`.
+
+`render` also writes a storyboard, with the picture at the end of each play that
+changes it, and the captions of a voice, as subtitles (`.srt`).
+
+## Tall videos
+
+For Shorts, Reels and TikTok, make the video tall: 1080 × 1920. Give the size to the
+command:
+
+```sh
+manimgx render scene.py -r 1080x1920
+```
+
+Or, to make every video of the file tall, put this line after `import manimgx as m`:
+
+```py
+m.config.pixel_width, m.config.pixel_height = 1080, 1920
+```
+
+A tall frame is 8 units wide and about 14.2 units high: the wide frame, turned. Both have
+the same square of 8 by 8 units in their middle, so a scene that stays in that square is
+the same in both. [Positions](positions.md#the-frame) shows the two frames. A square
+video, `-r 1080x1080`, is that square alone.
+
+## Preview
+
+`manimgx preview scene.py` plays the scene in a window. Each time that you save the file,
+the window plays the new version, from the same moment. If the new version has an error,
+the window shows the error.
+
+The window's keys are a video player's: Space plays and pauses, ← and → go back and
+forward 5 seconds, and ? shows all the keys. Its timeline shows each play of the scene,
+named by its line of code, or each section, if the scene has sections.
+
+## Check
+
+`manimgx check scene.py` runs the scene without making a video, so it takes a fraction of
+the time. It lists each play, with its time and its line of code. Then it lists the
+problems that a viewer would see at the end of each play:
+
+- a mobject that the frame cuts off;
+- texts that cover each other, a line through a text, or a fill over it;
+- text too small to read.
+
+```console
+$ manimgx check crowded.py
+crowded.py: Crowded, 3.00 s, 2 plays
+storyboard: Crowded.storyboard.png
+ #0 0.00– 2.00s crowded.py:8 Write(Text 'A title much too long for t…')
+ #1 2.00– 3.00s crowded.py:9 FadeIn(Text 'a note')
+layout: 2 problems
+ [1] t=2.0–3.0s (after crowded.py:8) title (Text 'A title much too long for the…'): 1.35 past the left edge, 1.35 past the right edge
+ [2] t=3.0s (after crowded.py:9) title (Text 'A title much too long for the…') and note (Text 'a note'): texts overlap
+```
+
+Each problem names the mobjects as your code names them, such as `title`. The
+storyboard outlines each problem in red. While there are problems, `check` ends with an
+error, so an AI agent can run it until the scene is right.
+
+## A still
+
+`manimgx still scene.py -t 1.5,end` draws the pictures at 1.5 seconds and at the end, in
+one PNG file.
+
+## Settings
+
+Set the video's settings on `m.config`, after the import: its size in pixels,
+`pixel_width` and `pixel_height`; its `frame_rate`; and its `background_color`:
+
+```python
+import manimgx as m
+
+m.config.background_color = m.WHITE
+
+
+class OnWhite(m.Scene):
+ def construct(self) -> None:
+ circle = m.Circle(radius=2, color=m.BLUE, fill_opacity=0.5)
+ label = m.Text("On white", color=m.BLACK)
+ label.next_to(circle, m.DOWN)
+ self.play(m.Create(circle), m.Write(label))
+```
+
+On the command line, `-r` and `--fps` set the size and the frame rate over the file's.
+
+## Slides
+
+A video can be a talk: it plays to the end of a slide, and waits until you continue.
+`self.next_section()` starts a new slide:
+
+```python
+import manimgx as m
+import numpy as np
+
+
+def two_sines(x: float) -> float:
+ return np.sin(x) + np.sin(3 * x) / 3
+
+
+class Talk(m.Scene):
+ def construct(self) -> None:
+ title = m.Text("Fourier series", font_size=72)
+ self.play(m.Write(title))
+ self.next_section("a sine", notes="Start with one sine.")
+ self.play(title.animate.to_edge(m.UP))
+ wave = m.FunctionGraph(np.sin, x_range=[-6, 6], color=m.BLUE)
+ self.play(m.Create(wave))
+ self.next_section("a sum")
+ total = m.FunctionGraph(two_sines, x_range=[-6, 6], color=m.YELLOW)
+ self.play(m.Transform(wave, total))
+```
+
+`manimgx present talk.py` makes the video, writes a web page next to it, and opens the
+page in your browser. → or a click goes to the next slide, ← goes back, F shows the full
+screen, and Shift+P opens the presenter view, with your notes, the next slide and a
+timer. To share the talk,
+send the page and the video together. `--pdf` also writes a handout, with a page for each
+slide.
+
+## From Python
+
+A scene can make its own video: `SquareToCircle().render("square_to_circle.mp4")`
+returns its [`Film`][manimgx.Film] and writes the video. Without a path, it runs the
+scene quickly, without drawing it, for example in a test.
+
+## In the browser
+
+manimgx runs in a web page, with no server: the page makes the video from your scene,
+and plays it. Install the npm package `manimgx`, import it in your page's script
+through your bundler, and put a scene in a `<manimgx-player>`:
+
+```html
+<script type="module">
+ import "manimgx";
+</script>
+
+<manimgx-player autoplay>
+ <script type="text/python">
+ import manimgx as m
+
+ class Euler(m.Scene):
+ def construct(self):
+ circle = m.Circle(color=m.BLUE, fill_opacity=0.5)
+ formula = m.MathTex(r"e^{i\pi} + 1 = 0").next_to(circle, m.DOWN)
+ self.play(m.Create(circle), m.Write(formula))
+ </script>
+</manimgx-player>
+```
+
+The player has the keys of the preview window. The first video on a page downloads
+Python ([Pyodide](https://pyodide.org)) and manimgx, about 26 MB; the browser keeps them
+for later. It needs WebGPU: Chrome and Edge 113 or later, or Safari 26. Two things don't
+work in the browser yet: shapes made from other shapes, such as `Union`, and Chinese,
+Japanese and Korean text.
diff --git a/docs/content/user-guide/sound-and-voice.md b/docs/content/user-guide/sound-and-voice.md
new file mode 100644
index 00000000..f0a6f567
--- /dev/null
+++ b/docs/content/user-guide/sound-and-voice.md
@@ -0,0 +1,97 @@
+# Sound and voice
+
+A video can have sound: a sound with an animation, music under the whole video, or a
+voice that explains. manimgx puts each sound at its moment in the video, and mixes them
+into one sound track.
+
+## Play a sound with an animation
+
+[`Sound`][manimgx.Sound] reads a sound from a file: WAV, MP3, AAC, FLAC and the other
+usual formats. Give it to `self.play` with an animation, and it starts with the
+animation:
+
+```py
+self.play(m.FadeIn(dot), m.Sound("click.wav"))
+```
+
+To start a sound at any moment, without an animation, use `self.add_sound`: the sound
+plays while the scene continues.
+
+```py
+self.add_sound(m.Sound("theme.mp3"))
+```
+
+A sound plays to its end. In `self.play`, the play lasts until the sound ends;
+`self.add_sound` doesn't wait. To stop a sound before its end, keep what `add_sound`
+gives back: `music = self.add_sound(...)`, then `music.stop(fade=2)`.
+
+## Change a sound
+
+A sound's methods make a changed sound: here, music 18 decibels quieter, which fades in
+for 2 seconds and plays until the video ends. A sound that loops never ends, so start it
+with `add_sound`: `self.play` refuses it.
+
+```py
+music = self.add_sound(m.Sound("theme.mp3").gain(-18).fade_in(2).loop())
+```
+
+The [`Sound`][manimgx.Sound] reference shows every change.
+
+## Say a line
+
+[`say`][manimgx.Scene.say] speaks a line with the scene's voice, and plays animations
+while it speaks. Put the words of each animation in brackets, and give the animations in
+the same order. The voice doesn't say the brackets:
+
+```python
+import manimgx as m
+
+
+class Derivative(m.Scene):
+ def construct(self) -> None:
+ square = m.MathTex("x^2", font_size=96).shift(2 * m.LEFT)
+ derivative = m.MathTex("2x", font_size=96).shift(2 * m.RIGHT)
+ self.add(square)
+ self.say(
+ "The derivative of [x squared] is [two x].",
+ m.Indicate(square),
+ m.Write(derivative),
+ )
+```
+
+Each animation starts with the first of its words. The scene waits until the line ends,
+so lines don't overlap. If you change the words, the animations follow the new words.
+
+## Voices
+
+The default voice is ElevenLabs' Eleven v3, on [fal.ai](https://fal.ai). It needs your
+fal.ai key in the `FAL_KEY` environment variable. To choose a different voice, set
+`voice` in the scene's class, next to `construct`:
+
+```py
+voice = m.voices.Fal(
+ "fal-ai/minimax/speech-2.8-hd",
+ voice_setting={"voice_id": "Calm_Woman", "emotion": "happy"},
+)
+```
+
+[`Fal`][manimgx.audio.fal.Fal] speaks with [five models][manimgx.audio.fal], and your
+editor shows the settings of each one. Any other text-to-speech service can be a voice
+too: a voice is a function from text to a [`Speech`][manimgx.Speech]. For a dialogue,
+give `say` a voice for one line: `self.say("Hello!", voice=other)`.
+
+manimgx keeps what the voice says in a folder named `voice/`, next to your scene's file.
+So the scene renders again without the service, even offline, and only a changed line
+goes to the service again. To use your own recording for a line, put it in place of
+that line's audio, with the same name.
+
+## Captions
+
+What the voice says becomes the video's captions. `manimgx render` writes them next to
+the video, as subtitles (`.srt`) that video players and video sites read.
+[`add_subcaption`][manimgx.Scene.add_subcaption] adds captions of your own.
+
+## Next
+
+[Rendering and sharing](rendering.md) shows the ways to make your video, check it, and
+share it.
diff --git a/src/manimgx/cli/present.html b/src/manimgx/cli/present.html
index f14a1980..e0021831 100644
--- a/src/manimgx/cli/present.html
+++ b/src/manimgx/cli/present.html
@@ -14,7 +14,7 @@
<div id="black"></div>
<div id="help">→ Space PageDown: next ← PageUp: back
Home End: first, last 1–9 then Enter: go to slide
-F: full screen B: black P: presenter view C: captions ?: this help</div>
+F: full screen B: black Shift+P: presenter view C: captions ?: this help</div>
<script>
"use strict";
const deck = DECK_JSON; // {fps, frames, sections: [{name, frame, type, notes}], captions: [[start, end, text]]}