The animation engine for agents: blazingly fast math and 3D videos with Manim's Python API, on a Rust GPU core.
Python
Write scene authoring guide
Sina Atalay50a03d1eb41b
diff --git a/docs/content/user-guide/animations.md b/docs/content/user-guide/animations.mdnew file mode 100644index 00000000..044f800a--- /dev/null+++ b/docs/content/user-guide/animations.md@@ -0,0 +1,120 @@+# Animations++An animation changes mobjects over time. [The basics](the-basics.md) showed the ones that+show and hide mobjects. This page shows how to animate any change, how to time an+animation, and how to play several together.++## Animate any change++Put `.animate` before a method, and `self.play` animates the change that the method makes:++```python+import manimgx as m+++class Changes(m.Scene):+ def construct(self) -> None:+ square = m.Square()+ self.play(m.Create(square))+ self.play(square.animate.shift(3 * m.RIGHT))+ self.play(square.animate.rotate(45 * m.DEGREES))+ self.play(square.animate.set_fill(m.BLUE, opacity=1))+ self.play(square.animate.scale(0.5).move_to(m.ORIGIN))+```++Without `.animate`, `square.shift(3 * m.RIGHT)` moves the square at once, with no+animation. With `.animate`, the square moves there in one second. You can chain several+changes after `.animate`, as the last line does, and they occur together.++## Turn one mobject into another++`m.ReplacementTransform` turns one mobject into another:++```python+import manimgx as m+++class SquareIntoCircle(m.Scene):+ def construct(self) -> None:+ square = m.Square(color=m.BLUE, fill_opacity=0.5)+ circle = m.Circle(color=m.PINK, fill_opacity=0.5)+ self.play(m.Create(square))+ self.play(m.ReplacementTransform(square, circle))+ self.play(circle.animate.shift(2 * m.UP))+```++After it, `circle` is in the video, and `square` is not. `m.Transform(square, circle)`+looks the same, but it changes `square` into the shape of the circle and keeps it in+the video: after it, you move `square`, not `circle`.++## Time an animation++Most animations take one second. To choose how long, give a `run_time`, in seconds:++```py+self.play(m.Create(circle), run_time=3)+```++Its `rate_func` sets how fast it goes at each moment. The default, `m.smooth`, starts+slowly, speeds up, and ends slowly. `m.linear` keeps one speed. Choose one below to see+how it moves:++<div class="mx-rates" data-rates="smooth linear rush_into rush_from there_and_back double_smooth running_start lingering ease_in_out_sine ease_in_back ease_out_elastic ease_out_bounce"></div>++```py+self.play(square.animate.shift(3 * m.RIGHT), rate_func=m.linear)+```++The [rate functions][manimgx.animation.easing] reference lists all of them.++## Play animations together++Give `self.play` several animations, and they play at the same time. The play lasts as+long as the longest one:++```python+import manimgx as m+++class Together(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ words = m.Text("A circle")+ words.next_to(circle, m.DOWN)+ self.play(m.Create(circle), m.Write(words))+ self.play(circle.animate.set_fill(m.RED, opacity=1), m.FadeOut(words))+```++## Play animations in turn++`m.LaggedStart` starts each animation a short time after the one before it. Its+`lag_ratio` sets when: 0.5 starts each one when the one before it is half done.++```python+import manimgx as m+++class InTurn(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ square = m.Square()+ triangle = m.Triangle()+ shapes = m.VGroup(circle, square, triangle)+ shapes.arrange(m.RIGHT, buff=1)+ self.play(+ m.LaggedStart(+ m.Create(circle), m.Create(square), m.Create(triangle), lag_ratio=0.5+ )+ )+```++`m.Succession` plays its animations one after the other, in one play. Use it when the+steps are a part of a larger play: for example, to move a shape in three steps while a+title is written.++The [reference](../reference/animations/index.md) shows every animation.++## Next++[Text and math](text-and-math.md) shows how to write words and formulas, and how to+animate them.diff --git a/docs/content/user-guide/graphs.md b/docs/content/user-guide/graphs.mdnew file mode 100644index 00000000..af5d4f55--- /dev/null+++ b/docs/content/user-guide/graphs.md@@ -0,0 +1,95 @@+# Graphs++Axes are a mobject with their own numbers on them. Use them to draw the graph of a+function, or of data.++## Axes and a graph++```python+import manimgx as m+++def square(x: float) -> float:+ return x**2+++class Parabola(m.Scene):+ def construct(self) -> None:+ axes = m.Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=8, y_length=5)+ axes.add_coordinates()+ graph = axes.plot(square, color=m.BLUE)+ self.play(m.Create(axes))+ self.play(m.Create(graph))+```++- `x_range=[-3, 3, 1]` puts the numbers from −3 to 3 on the x-axis, with a tick at every+ 1. `y_range` does the same for the y-axis.+- `x_length` and `y_length` set how long the axes are, in units of the frame.+- `add_coordinates` writes the numbers at the ticks.+- `axes.plot` draws the graph of a Python function of `x`.++## The axes' own numbers++The axes have their own coordinates. On the graph above, the point where `x` is 2 and+`y` is 4 is not at `[2, 4, 0]` in the frame. `axes.c2p(2, 4)` ("coordinates to point")+gives its point in the frame. Use it to put mobjects on a graph:++```python+import manimgx as m+++def square(x: float) -> float:+ return x**2+++class OnTheGraph(m.Scene):+ def construct(self) -> None:+ axes = m.Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=8, y_length=5)+ graph = axes.plot(square, color=m.BLUE)+ dot = m.Dot(axes.c2p(2, 4), color=m.YELLOW)+ label = m.MathTex("(2, 4)")+ label.next_to(dot, m.RIGHT)+ self.add(axes, graph, dot, label)+```++## Labels and areas++The axes make the parts that explain a graph:++```python+import manimgx as m+++def curve(x: float) -> float:+ return x**2 / 4+++class Area(m.Scene):+ def construct(self) -> None:+ axes = m.Axes(x_range=[0, 4, 1], y_range=[0, 4, 1], x_length=8, y_length=5.5)+ axes.add_coordinates()+ names = axes.get_axis_labels("x", "y")+ graph = axes.plot(curve, color=m.BLUE)+ label = axes.get_graph_label(graph, r"y = \frac{x^2}{4}", x_val=4)+ area = axes.get_area(graph, x_range=[1, 3], opacity=0.5)+ self.play(m.Create(axes), m.Write(names))+ self.play(m.Create(graph), m.Write(label))+ self.play(m.FadeIn(area))+ self.wait()+```++- `get_axis_labels` names the axes.+- `get_graph_label` writes a label, in LaTeX, at the end of a graph, or at `x_val`.+- `get_area` fills the area under a graph, between two values of `x`.++These methods make new mobjects. Add them to the scene, or animate them, as the example+does.++`m.NumberPlane()`, the grid of [Positions](positions.md), is axes too: axes that fill the+frame, with the frame's own coordinates. The [plotting reference][manimgx.mobjects.plotting]+shows every kind of axes and graph.++## Next++[Updaters](updaters.md) shows how to make a mobject follow another, such as a dot that+moves along a graph.diff --git a/docs/content/user-guide/mobjects.md b/docs/content/user-guide/mobjects.mdnew file mode 100644index 00000000..3b142f44--- /dev/null+++ b/docs/content/user-guide/mobjects.md@@ -0,0 +1,148 @@+# Mobjects++A mobject is anything that you can show in a video. This page shows the kinds of+mobjects, and how to change their color, size and angle.++## Shapes++```python+import manimgx as m+++class Shapes(m.Scene):+ def construct(self) -> None:+ circle = m.Circle(radius=1)+ square = m.Square(side_length=2)+ rectangle = m.Rectangle(width=3, height=2)+ triangle = m.Triangle()+ star = m.Star()+ shapes = m.VGroup(circle, square, rectangle, triangle, star)+ shapes.arrange(m.RIGHT, buff=0.6)+ self.add(shapes)+```++Each shape takes its size when you make it: a circle its `radius`, a square its+`side_length`, a rectangle its `width` and `height`. Without them, a shape has a size of+its own: a circle's radius is 1, and a square's side is 2.++To make a shape of your own, give `m.Polygon` its corners:+`m.Polygon([0, 0, 0], [3, 0, 0], [0, 2, 0])`.++## Lines, arrows and dots++A line goes from one point to another:++```python+import manimgx as m+++class Lines(m.Scene):+ def construct(self) -> None:+ line = m.Line([-5, 1, 0], [-1, 1, 0])+ arrow = m.Arrow([1, 1, 0], [5, 1, 0])+ dashed = m.DashedLine([-5, -1, 0], [-1, -1, 0])+ dot = m.Dot([3, -1, 0])+ self.add(line, arrow, dashed, dot)+```++An arrow stops a little before its points, so that it doesn't cover what it points at.+To make it touch them, give `buff=0`. A dot is a small filled circle at a point.++## Text and formulas++`m.Text` shows text, and `m.MathTex` shows a formula, written in LaTeX:++```python+import manimgx as m+++class TextAndFormula(m.Scene):+ def construct(self) -> None:+ text = m.Text("Hello, world")+ formula = m.MathTex(r"e^{i\pi} + 1 = 0")+ lines = m.VGroup(text, formula)+ lines.arrange(m.DOWN, buff=1)+ self.add(lines)+```++Write a formula in a raw string, `r"..."`, so that Python keeps its backslashes.+[Text and math](text-and-math.md) shows more.++## Color++Give a mobject its color when you make it:++```python+import manimgx as m+++class Colors(m.Scene):+ def construct(self) -> None:+ outline = m.Circle(color=m.BLUE)+ filled = m.Circle(color=m.BLUE, fill_opacity=0.5)+ thick = m.Circle(color=m.YELLOW, stroke_width=12)+ circles = m.VGroup(outline, filled, thick)+ circles.arrange(m.RIGHT, buff=1)+ self.add(circles)+```++- `color` colors the outline and the inside.+- `fill_opacity` fills the inside: 0 is empty, 1 is solid. Most shapes are empty+ unless you fill them.+- `stroke_width` sets the width of the outline: 4 for most shapes, and 6 for an+ arrow, unless you give another.++manimgx has names for colors: `m.WHITE`, `m.GREY`, `m.BLUE`, `m.TEAL`, `m.GREEN`,+`m.YELLOW`, `m.GOLD`, `m.ORANGE`, `m.RED`, `m.PINK`, `m.PURPLE` and more. Most of them+also come in five shades: `m.BLUE_A` is the lightest blue, and `m.BLUE_E` the+darkest. You can also give a color as a hex code, such as `"#58C4DD"`.++To change a color later, use `set_color`, `set_fill` or `set_stroke`:+`circle.set_fill(m.RED, opacity=1)`.++## Size and angle++`scale` multiplies the size of a mobject, and `rotate` turns it counterclockwise:++```python+import manimgx as m+++class SizeAndAngle(m.Scene):+ def construct(self) -> None:+ small = m.Square()+ small.scale(0.5)+ turned = m.Square()+ turned.rotate(45 * m.DEGREES)+ large = m.Square()+ large.scale(1.5)+ squares = m.VGroup(small, turned, large)+ squares.arrange(m.RIGHT, buff=1)+ self.add(squares)+```++`scale(2)` makes a mobject twice as large, and `scale(0.5)` half as large. Its center+stays where it is. `45 * m.DEGREES` is an angle of 45 degrees.++## Groups++A group is a mobject made of other mobjects. When you move, scale, color or animate a+group, you do it to every mobject in it. `group[0]` is the first one, `group[1]` the+second.++```py+shapes = m.VGroup(circle, square, triangle)+shapes.set_color(m.YELLOW) # all three turn yellow+shapes[0].scale(2) # the circle grows+```++## What covers what++A mobject that you add later covers a mobject that you added before. To bring a+mobject to the front, give it a higher z-index: `circle.set_z_index(1)`.++The [reference](../reference/mobjects/index.md) shows every kind of mobject.++## Next++Your mobjects are in place. [Animations](animations.md) shows how to move and change them.diff --git a/docs/content/user-guide/positions.md b/docs/content/user-guide/positions.mdnew file mode 100644index 00000000..821e3d2e--- /dev/null+++ b/docs/content/user-guide/positions.md@@ -0,0 +1,209 @@+# Positions++You choose where each mobject is. manimgx doesn't arrange them for you: it puts each one+at the position that you give it. This page shows how positions work.++## The frame++The frame is the rectangle that the video shows. Positions are measured in units, and the+frame's short side is 8 units, in a wide video and in a tall one:++=== "16:9"++ ```python fold title="The figure's code"+ import manimgx as m+++ class FrameWide(m.Scene):+ def construct(self) -> None:+ self.add(frame_figure())+++ def frame_figure() -> m.VGroup:+ w, h = m.config.frame_width / 2, m.config.frame_height / 2+ grid = m.NumberPlane(+ background_line_style={"stroke_color": m.GREY_D, "stroke_width": 1},+ axis_config={"stroke_color": m.GREY_B, "stroke_width": 2},+ )+ center = m.Dot(color=m.YELLOW)+ center_label = m.MathTex("[0, 0, 0]", font_size=30, color=m.YELLOW)+ center_label.next_to(center, m.DR, buff=0.1)+ edges = m.VGroup(+ m.MathTex(f"y = {h:g}", font_size=34).next_to([0, h, 0], m.DOWN, buff=0.2),+ m.MathTex(f"y = {-h:g}", font_size=34).next_to([0, -h, 0], m.UP, buff=0.2),+ m.MathTex(f"x = {w:.1f}", font_size=34).next_to([w, 0, 0], m.LEFT, buff=0.2),+ m.MathTex(f"x = {-w:.1f}", font_size=34).next_to([-w, 0, 0], m.RIGHT, buff=0.2),+ )+ for label in edges:+ label.add_background_rectangle(opacity=1, buff=0.08)+ square = m.DashedVMobject(+ m.Square(side_length=8, color=m.BLUE, stroke_width=3), num_dashes=64+ )+ return m.VGroup(grid, square, center, center_label, edges)+ ```++=== "9:16"++ ```python fold title="The figure's code"+ import manimgx as m++ m.config.pixel_width, m.config.pixel_height = 1080, 1920+++ class FrameTall(m.Scene):+ def construct(self) -> None:+ self.add(frame_figure())+++ def frame_figure() -> m.VGroup:+ w, h = m.config.frame_width / 2, m.config.frame_height / 2+ grid = m.NumberPlane(+ background_line_style={"stroke_color": m.GREY_D, "stroke_width": 1},+ axis_config={"stroke_color": m.GREY_B, "stroke_width": 2},+ )+ center = m.Dot(color=m.YELLOW)+ center_label = m.MathTex("[0, 0, 0]", font_size=30, color=m.YELLOW)+ center_label.next_to(center, m.DR, buff=0.1)+ edges = m.VGroup(+ m.MathTex(f"y = {h:.1f}", font_size=34).next_to([0, h, 0], m.DOWN, buff=0.2),+ m.MathTex(f"y = {-h:.1f}", font_size=34).next_to([0, -h, 0], m.UP, buff=0.2),+ m.MathTex(f"x = {w:g}", font_size=34).next_to([w, 0, 0], m.LEFT, buff=0.2),+ m.MathTex(f"x = {-w:g}", font_size=34).next_to([-w, 0, 0], m.RIGHT, buff=0.2),+ )+ for label in edges:+ label.add_background_rectangle(opacity=1, buff=0.08)+ square = m.DashedVMobject(+ m.Square(side_length=8, color=m.BLUE, stroke_width=3), num_dashes=64+ )+ return m.VGroup(grid, square, center, center_label, edges)+ ```++A position is a point, written as three numbers: `[x, y, 0]`.++- The center of the frame is `[0, 0, 0]`.+- `x` grows to the right, and `y` grows upward.+- The third number is the depth, for 3D. In a flat scene, it is 0.++A video is wide (16:9) unless you make it tall (9:16). To make it tall, put this line+after `import manimgx as m`:++```py+m.config.pixel_width, m.config.pixel_height = 1080, 1920+```++Or give the size to the command: `manimgx render scene.py -r 1080x1920`. Both frames+have the same square in their middle, 8 units on each side. What you put in that square+looks the same in both.++## Put a mobject at a point++`move_to` puts the center of a mobject at a point:++```python+import manimgx as m+++class Points(m.Scene):+ def construct(self) -> None:+ grid = m.NumberPlane()+ grid.add_coordinates()+ yellow = m.Dot(color=m.YELLOW)+ yellow.move_to([3, 2, 0])+ blue = m.Dot(color=m.BLUE)+ blue.move_to([-4, -1, 0])+ self.add(grid, yellow, blue)+```++`m.NumberPlane()` draws a line at every unit, and `add_coordinates` numbers them. A grid+helps you see positions while you work.++## Directions++manimgx has names for directions. Each name is a point:++| Name | Point |+| --- | --- |+| `m.RIGHT`, `m.LEFT` | `[1, 0, 0]`, `[-1, 0, 0]` |+| `m.UP`, `m.DOWN` | `[0, 1, 0]`, `[0, -1, 0]` |+| `m.UR`, `m.UL`, `m.DR`, `m.DL` | the diagonals: up and right `[1, 1, 0]`, up and left, down and right, down and left |+| `m.ORIGIN` | `[0, 0, 0]`, the center |++Multiply a direction by a number, and add directions together, to make other points:+`3 * m.RIGHT + 2 * m.UP` is `[3, 2, 0]`.++To move a mobject by an amount from where it is, use `shift`: `dot.shift(2 * m.LEFT)`+moves the dot 2 units to the left.++## Put a mobject next to another++`next_to` puts a mobject next to another one, in a direction:++```python+import manimgx as m+++class NextTo(m.Scene):+ def construct(self) -> None:+ square = m.Square()+ above = m.Text("above")+ above.next_to(square, m.UP)+ right = m.Text("right")+ right.next_to(square, m.RIGHT)+ self.add(square, above, right)+```++The gap is 0.25 units. To change it, give `buff`: `above.next_to(square, m.UP, buff=1)`.++## Put a mobject at an edge++`to_edge` moves a mobject to an edge of the frame, and `to_corner` moves it to a corner.+They leave a margin of 0.5 units:++```python+import manimgx as m+++class Edges(m.Scene):+ def construct(self) -> None:+ title = m.Text("A title")+ title.to_edge(m.UP)+ note = m.Text("a note", font_size=32)+ note.to_corner(m.DR)+ self.add(title, note)+```++Because they find the frame's edges, they work in both a wide and a tall video.++## Line mobjects up++A group holds several mobjects: `m.VGroup(circle, square, triangle)`. `arrange` puts its+mobjects in a line, each one next to the one before it, and puts the line in the middle of+the frame:++```python+import manimgx as m+++class Row(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ square = m.Square()+ triangle = m.Triangle()+ shapes = m.VGroup(circle, square, triangle)+ shapes.arrange(m.RIGHT, buff=1)+ self.add(shapes)+```++`m.RIGHT` makes a row, and `m.DOWN` makes a column. `buff` is the gap between them. A+group moves as one mobject: `shapes.to_edge(m.DOWN)` moves all three shapes.++## Chain the calls++`move_to`, `shift`, `next_to`, `to_edge` and `arrange` give back the mobject. So you can+write the calls one after the other: `m.Text("A title").to_edge(m.UP)` makes a text and+moves it to the top.++## Next++[Mobjects](mobjects.md) shows the kinds of mobjects that you can place, and how to+change their color, size and angle.diff --git a/docs/content/user-guide/quickstart.md b/docs/content/user-guide/quickstart.mdnew file mode 100644index 00000000..7287a556--- /dev/null+++ b/docs/content/user-guide/quickstart.md@@ -0,0 +1,151 @@+# Quickstart++There are two ways to start. Choose one.++## With an AI agent++Paste this into Claude Code or Codex:++``` { .text .mx-prompt }+Follow https://manimgx.academa.ai/llms.txt to make me a short animation of a square turning into a circle, and open it.+```++That's it. The agent installs manimgx, writes the code, makes the video and opens it. To+get a different video, change the words after "make me". If the agent asks to use the+network or the GPU, allow it.++## By hand++### 1. Install manimgx++=== "uv"++ If you don't have [uv](https://docs.astral.sh/uv/), install it:++ === "macOS and Linux"++ ```sh+ curl -LsSf https://astral.sh/uv/install.sh | sh+ ```++ === "Windows"++ ```powershell+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"+ ```++ Then close the terminal and open a new one, so that it finds uv. Make a folder for+ your videos, with manimgx in it (uv also installs Python 3.14 if you don't have it):++ ```sh+ uv init --bare --python 3.14 my-videos+ cd my-videos+ uv add manimgx+ ```++=== "pip"++ You need Python 3.13 or 3.14. Make a folder for your videos, with a virtual+ environment, and install manimgx in it:++ ```sh+ mkdir my-videos+ cd my-videos+ python3 -m venv .venv # Windows: py -m venv .venv+ source .venv/bin/activate # Windows: .venv\Scripts\activate+ pip install manimgx+ ```++ If Windows' PowerShell refuses to run the activate script, allow it once with+ `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`.++### 2. Set up your editor++Set up [ty](https://docs.astral.sh/ty/) in your editor. ty checks your code as you type.+It completes manimgx's names, shows what each one does, and underlines many of your+mistakes before you make a video.++=== "VS Code"++ Install the [ty extension](https://marketplace.visualstudio.com/items?itemName=astral-sh.ty).+ Cursor, Windsurf and the other editors made from VS Code have it in their Extensions+ view too. Then open your folder, `my-videos`, with **File > Open Folder**.++=== "Zed"++ Zed includes ty. To turn it on, open your settings file (++cmd+alt+comma++ on a Mac,+ ++ctrl+alt+comma++ on Windows and Linux), and paste these lines right after its first+ `{`:++ ```json+ "languages": {+ "Python": {+ "language_servers": ["ty", "!basedpyright", "..."]+ }+ },+ ```++ Then open your folder, `my-videos`, with **File > Open**.++ty finds manimgx in the folder's `.venv`, which step 1 made.++### 3. Write a scene++In your folder, make a file named `scene.py`, and write this code in it:++```python title="scene.py"+import manimgx as m+++class SquareToCircle(m.Scene):+ def construct(self) -> None:+ square = m.Square(side_length=3, color=m.BLUE, fill_opacity=0.5)+ circle = m.Circle(radius=1.6, color=m.PINK, fill_opacity=0.5)+ self.play(m.Create(square))+ self.play(m.Transform(square, circle))+ self.wait()+```++### 4. Preview it++Open your editor's terminal (++ctrl+grave++), and run:++=== "uv"++ ```sh+ uv run manimgx preview scene.py+ ```++ With uv, start every `manimgx` command with `uv run`. The rest of these docs write+ the commands without it.++=== "pip"++ ```sh+ manimgx preview scene.py+ ```++ In a new terminal, activate the environment first, as in step 1.++A window plays your scene. Put it next to your editor. Each time that you save+`scene.py`, the window plays the new version. Try it: change `m.PINK` to `m.YELLOW`, and+save.++### 5. Make the video++=== "uv"++ ```sh+ uv run manimgx render scene.py+ ```++=== "pip"++ ```sh+ manimgx render scene.py+ ```++manimgx writes the video, `SquareToCircle.mp4`, next to `scene.py`. It's the video above+the code in step 3. For a tall video (Shorts, Reels, TikTok), add `-r 1080x1920`.++You are ready. Next, [The basics](the-basics.md) explains how a scene makes a video.diff --git a/docs/content/user-guide/text-and-math.md b/docs/content/user-guide/text-and-math.mdnew file mode 100644index 00000000..04553323--- /dev/null+++ b/docs/content/user-guide/text-and-math.md@@ -0,0 +1,105 @@+# Text and math++manimgx sets text and formulas itself, with [Typst](https://typst.app) and fonts that come+with it. You don't install LaTeX or fonts, and your text looks the same on every computer.++## Text++`m.Text` shows text exactly as you write it. A new line (`\n`) starts a new line:++```python+import manimgx as m+++class Words(m.Scene):+ def construct(self) -> None:+ title = m.Text("The Pythagorean theorem", font_size=64)+ note = m.Text("for a right triangle", font_size=36, color=m.GREY_B)+ note.next_to(title, m.DOWN)+ self.play(m.Write(title))+ self.play(m.FadeIn(note))+```++- `font_size` sets the size: 48 unless you give another.+- `font` sets the font: `"sans-serif"`, `"monospace"`, or the name of a font on your+ computer. The default is New Computer Modern, the font of LaTeX.+- `t2c` colors parts of the text: `m.Text("red and blue", t2c={"red": m.RED, "blue": m.BLUE})`.++Text is a mobject like any other: you can move it, scale it, color it and animate it.++## Formulas++`m.MathTex` shows a formula, written in LaTeX math. Write it in a raw string, `r"..."`,+so that Python keeps its backslashes:++```python+import manimgx as m+++class Formula(m.Scene):+ def construct(self) -> None:+ formula = m.MathTex(r"\int_0^1 x^2 \, dx = \frac{1}{3}", font_size=72)+ self.play(m.Write(formula))+```++Fractions, roots, sums and integrals, matrices, `cases`, Greek letters, `\mathbb` and+`\text` work. LaTeX packages and `\def` don't. If manimgx doesn't know a command, its+error names the command.++`m.Tex` is for text with math in it: `m.Tex(r"The area is $\pi r^2$.")`.++## Parts of a formula++Give `m.MathTex` several strings, and each one becomes a part that you can color or+animate on its own. `formula[2]` is the third part:++```python+import manimgx as m+++class Parts(m.Scene):+ def construct(self) -> None:+ formula = m.MathTex("a^2", "+", "b^2", "=", "c^2", font_size=96)+ formula[2].set_color(m.YELLOW)+ self.play(m.Write(formula))+ self.play(m.Indicate(formula[2]))+```++## Change a formula into another++`m.TransformMatchingTex` moves each part of a formula to the part with the same LaTeX+in another formula. The parts that don't match fade out and in:++```python+import manimgx as m+++class Rearrange(m.Scene):+ def construct(self) -> None:+ before = m.MathTex("a^2", "+", "b^2", "=", "c^2", font_size=96)+ after = m.MathTex("a^2", "=", "c^2", "-", "b^2", font_size=96)+ before[2].set_color(m.YELLOW)+ after[4].set_color(m.YELLOW)+ self.play(m.Write(before))+ self.play(m.TransformMatchingTex(before, after))+ self.wait()+```++## Numbers++`m.DecimalNumber(3.14)` shows a number. Its `set_value` shows a different one in its+place, so a number can count up or down as a scene plays: [Updaters](updaters.md) shows+how.++## Typst++If you know [Typst](https://typst.app), write in it directly: `m.Typst` takes Typst+markup, and `m.MathTypst` a formula in Typst's math syntax.++```py+m.Typst("*Bold*, _italic_, and math: $sum_(k=1)^n k = (n(n+1))/2$")+```++## Next++[Graphs](graphs.md) shows how to draw axes and plot functions, with labels.diff --git a/docs/content/user-guide/the-basics.md b/docs/content/user-guide/the-basics.mdnew file mode 100644index 00000000..644da06d--- /dev/null+++ b/docs/content/user-guide/the-basics.md@@ -0,0 +1,113 @@+# The basics++With manimgx, you write a short Python program, and manimgx makes a video of it. This+page shows how.++## A program makes a video++Here is a manimgx program:++```python title="hello.py" show="code"+import manimgx as m+++class Hello(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ self.play(m.Create(circle))+ self.wait()+```++Save it in a file named `hello.py`. Then, in a terminal, in the same folder, run this+command (with uv, start it with `uv run`, as the [Quickstart](quickstart.md#4-preview-it)+says):++```sh+manimgx render hello.py+```++manimgx makes this video, `Hello.mp4`, next to the file:++```python show="film"+import manimgx as m+++class Hello(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ self.play(m.Create(circle))+ self.wait()+```++That is how you work with manimgx: you write a program, and manimgx makes a video of it.++## The program, line by line++`import manimgx as m`+: gives you all of manimgx under a short name, `m`: `m.Scene`, `m.Circle`, `m.Create`.++`class Hello(m.Scene):`+: makes a **scene**. A scene is one video. Its name is the name of the video: the+ scene `Hello` makes `Hello.mp4`.++`def construct(self) -> None:`+: tells what happens in the video. manimgx runs `construct` from top to bottom, and+ each line adds to the video in that order.++`circle = m.Circle()`+: makes a circle. A circle is a **mobject**: anything that you can show in a video is+ a mobject. Shapes, lines, text, formulas and graphs are mobjects. But making a mobject+ doesn't show it: at this line, the video is still empty.++`self.play(m.Create(circle))`+: plays an **animation**: `m.Create(circle)` draws the circle, in one second. After+ that, the circle is in the video, and it stays there.++`self.wait()`+: keeps the picture still for one second. So the video is two seconds long.++## One step after another++Each `self.play` starts when the one before it ends. Time passes only in `play` and in+`wait`:++```python+import manimgx as m+++class Steps(m.Scene):+ def construct(self) -> None:+ circle = m.Circle()+ words = m.Text("Hello!")+ self.play(m.Create(circle)) # from 0 to 1 second+ self.play(m.FadeOut(circle)) # from 1 to 2 seconds+ self.play(m.Write(words)) # from 2 to 3 seconds+ self.wait(2) # from 3 to 5 seconds+```++These animations show and hide mobjects. You will use them most:++- `m.Create(...)` draws a shape.+- `m.Write(...)` writes a text or a formula.+- `m.FadeIn(...)` fades a mobject in. `m.FadeOut(...)` fades it out, and removes it.++`self.wait(2)` waits 2 seconds. Without a number, it waits 1 second.++## Show a mobject at once++To show a mobject with no animation, add it: `self.add(circle)`. The circle is in the+video from that moment. `self.remove(circle)` removes it at once.++## Several scenes in one file++A file can have several scenes, and each one is a video. To make one of them, give its+name after the file:++```sh+manimgx render hello.py Steps+```++## Next++So far, every mobject appears in the middle of the video. [Positions](positions.md) shows+how to put each one where you want it.diff --git a/docs/content/user-guide/updaters.md b/docs/content/user-guide/updaters.mdnew file mode 100644index 00000000..41c3b3ca--- /dev/null+++ b/docs/content/user-guide/updaters.md@@ -0,0 +1,112 @@+# Updaters++Sometimes a mobject must follow a rule while others move: a label stays above a dot, or a+number shows where a dot is. An updater is a function that keeps such a rule. manimgx+calls it at every frame.++## Follow another mobject++```python+import manimgx as m+++class Follow(m.Scene):+ def construct(self) -> None:+ dot = m.Dot(color=m.YELLOW)+ label = m.Text("dot", font_size=32)++ def stay_above(mobject: m.Mobject) -> None:+ mobject.next_to(dot, m.UP)++ label.add_updater(stay_above)+ self.add(dot, label)+ self.play(dot.animate.shift(4 * m.RIGHT))+ self.play(dot.animate.shift(3 * m.DOWN))+```++`label.add_updater(stay_above)` makes manimgx call `stay_above(label)` at every frame. So+the label stays above the dot, wherever the dot goes. `label.clear_updaters()` stops it.++## A number that you animate++A [`ValueTracker`][manimgx.ValueTracker] holds a number. It doesn't show anything, but+you can animate its number, and updaters can read it. So one animation can move many+mobjects:++```python+import manimgx as m+++class Counter(m.Scene):+ def construct(self) -> None:+ x = m.ValueTracker(0)+ number = m.DecimalNumber(0, font_size=96)++ def show_x(mobject: m.DecimalNumber) -> None:+ mobject.set_value(x.get_value())++ number.add_updater(show_x)+ self.add(number)+ self.play(x.animate.set_value(10), run_time=3)+```++`x.animate.set_value(10)` changes the number from 0 to 10, in 3 seconds.+`x.get_value()` reads it.++## Make a mobject again at every frame++`m.always_redraw` takes a function that makes a mobject, and makes it again at every+frame. Here, a dot rides a graph as a tracker moves:++```python+import manimgx as m+++def curve(x: float) -> float:+ return x**2 / 4+++class Ride(m.Scene):+ def construct(self) -> None:+ axes = m.Axes(x_range=[0, 5, 1], y_range=[0, 7, 1], x_length=8, y_length=5)+ graph = axes.plot(curve, color=m.BLUE)+ x = m.ValueTracker(1)++ def make_dot() -> m.Dot:+ point = axes.c2p(x.get_value(), curve(x.get_value()))+ return m.Dot(point, color=m.YELLOW)++ dot = m.always_redraw(make_dot)+ self.add(axes, graph, dot)+ self.play(x.animate.set_value(4.5), run_time=3)+```++## Motion that goes on++An updater can also take `dt`: the time, in seconds, since it last ran. Use it for motion+that goes on as time passes, in plays and in waits:++```python+import manimgx as m+++class Spin(m.Scene):+ def construct(self) -> None:+ square = m.Square(color=m.BLUE, fill_opacity=0.5)++ def turn(mobject: m.Mobject, dt: float) -> None:+ mobject.rotate(dt * m.PI)++ square.add_updater(turn)+ self.add(square)+ self.wait(2)+```++`dt * m.PI` turns the square half a turn each second. Updaters that take `dt` can also+simulate physics: the [Gallery](../gallery/index.md) has examples, such as+[a spinning top](../gallery/heavy-top.md).++## Next++[Camera and 3D](camera-and-3d.md) shows how to move the camera, and how to make scenes+in three dimensions.