manimgl-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

How to use

使用方法

Read individual rule files for detailed explanations and code examples:
阅读单个规则文件获取详细说明和代码示例:

Core Concepts

核心概念

  • rules/scenes.md - InteractiveScene, Scene types, and construct method
  • rules/mobjects.md - Mobject types, VMobject, Groups, and positioning
  • rules/animations.md - Animation classes, playing animations, and timing
  • rules/scenes.md - InteractiveScene、场景类型和construct方法
  • rules/mobjects.md - Mobject类型、VMobject、组和定位
  • rules/animations.md - 动画类、播放动画和时间控制

Creation & Transformation

创建与变换

  • rules/creation-animations.md - ShowCreation, Write, FadeIn, DrawBorderThenFill
  • rules/transform-animations.md - Transform, ReplacementTransform, TransformMatchingTex
  • rules/animation-groups.md - LaggedStart, Succession, AnimationGroup
  • rules/creation-animations.md - ShowCreation、Write、FadeIn、DrawBorderThenFill
  • rules/transform-animations.md - Transform、ReplacementTransform、TransformMatchingTex
  • rules/animation-groups.md - LaggedStart、Succession、AnimationGroup

Text & Math

文本与数学

  • rules/tex.md - Tex class, raw strings R"...", and LaTeX rendering
  • rules/text.md - Text mobjects, fonts, and styling
  • rules/t2c.md - tex_to_color_map (t2c) for coloring math expressions
  • rules/tex.md - Tex类、原始字符串R"..."和LaTeX渲染
  • rules/text.md - Text mobjects、字体和样式
  • rules/t2c.md - tex_to_color_map(t2c)用于数学表达式着色

Styling & Appearance

样式与外观

  • rules/colors.md - Color constants, gradients, RGB, hex, GLSL coloring
  • rules/styling.md - Fill, stroke, opacity, backstroke, gloss, shadow
  • rules/colors.md - 颜色常量、渐变、RGB、十六进制、GLSL着色
  • rules/styling.md - 填充、描边、透明度、背描边、光泽、阴影

3D & Camera

3D与相机

  • rules/3d.md - 3D objects, surfaces, Sphere, Torus, parametric surfaces, lighting
  • rules/camera.md - frame.reorient(), Euler angles, fix_in_frame(), camera animations
  • rules/3d.md - 3D对象、曲面、Sphere、Torus、参数化曲面、光照
  • rules/camera.md - frame.reorient()、欧拉角、fix_in_frame()、相机动画

Interactive Development

交互式开发

  • rules/interactive.md - Interactive mode with
    -se
    flag, checkpoint_paste()
  • rules/frame.md - self.frame, camera control, reorient, and zooming
  • rules/embedding.md - self.embed() for IPython debugging, touch() mode
  • rules/interactive.md - 带-se参数的交互模式、checkpoint_paste()
  • rules/frame.md - self.frame、相机控制、重定向和缩放
  • rules/embedding.md - 用于IPython调试的self.embed()、touch()模式

Configuration & CLI

配置与CLI

  • rules/cli.md - manimgl command, flags (-w, -o, -se, -l, -h), rendering options
  • rules/config.md - custom_config.yml, directories, camera settings, quality presets
  • rules/cli.md - manimgl命令、参数(-w、-o、-se、-l、-h)、渲染选项
  • rules/config.md - custom_config.yml、目录、相机设置、质量预设

Working Examples

示例工程

Complete, tested example files demonstrating common patterns:
  • examples/basic_animations.py - Basic shapes, text, and animations
  • examples/math_visualization.py - LaTeX equations and mathematical content
  • examples/graph_plotting.py - Axes, functions, and graphing
  • examples/3d_visualization.py - 3D scenes with camera control and surfaces
  • examples/updater_patterns.py - Dynamic animations with updaters
完整的测试示例文件,展示常见模式:
  • examples/basic_animations.py - 基础图形、文本和动画
  • examples/math_visualization.py - LaTeX公式和数学内容
  • examples/graph_plotting.py - 坐标轴、函数和绘图
  • examples/3d_visualization.py - 带相机控制和曲面的3D场景
  • examples/updater_patterns.py - 带更新器的动态动画

Scene Templates

场景模板

Copy and modify these templates to start new projects:
  • templates/basic_scene.py - Standard 2D scene template
  • templates/interactive_scene.py - InteractiveScene with self.embed()
  • templates/3d_scene.py - 3D scene with frame.reorient()
  • templates/math_scene.py - Mathematical derivations and equations
复制并修改这些模板以启动新项目:
  • templates/basic_scene.py - 标准2D场景模板
  • templates/interactive_scene.py - 带self.embed()的InteractiveScene
  • templates/3d_scene.py - 带frame.reorient()的3D场景
  • templates/math_scene.py - 数学推导和公式场景

Quick Reference

快速参考

Basic Scene Structure

基础场景结构

python
from manimlib import *

class MyScene(InteractiveScene):
    def construct(self):
        # Create mobjects
        circle = Circle()

        # Add to scene (static)
        self.add(circle)

        # Or animate
        self.play(ShowCreation(circle))  # Note: ShowCreation, not Create

        # Wait
        self.wait(1)
python
from manimlib import *

class MyScene(InteractiveScene):
    def construct(self):
        # 创建mobjects
        circle = Circle()

        # 添加到场景(静态)
        self.add(circle)

        # 或者添加动画
        self.play(ShowCreation(circle))  # 注意:使用ShowCreation,而非Create

        # 等待
        self.wait(1)

Render Command

渲染命令

bash
undefined
bash
undefined

Render and preview

渲染并预览

manimgl scene.py MyScene
manimgl scene.py MyScene

Interactive mode - drop into shell at line 15

交互模式 - 在第15行进入shell

manimgl scene.py MyScene -se 15
manimgl scene.py MyScene -se 15

Write to file

写入文件

manimgl scene.py MyScene -w
manimgl scene.py MyScene -w

Low quality for testing

低质量测试

manimgl scene.py MyScene -l
undefined
manimgl scene.py MyScene -l
undefined

Key Differences from ManimCE

与Manim社区版的主要区别

FeatureManimGL (3b1b)Manim Community
Import
from manimlib import *
from manim import *
CLI
manimgl
manim
Math text
Tex(R"\pi")
MathTex(r"\pi")
Scene
InteractiveScene
Scene
Create anim
ShowCreation
Create
Camera
self.frame
self.camera.frame
Fix in frame
mob.fix_in_frame()
self.add_fixed_in_frame_mobjects(mob)
Package
manimgl
(PyPI)
manim
(PyPI)
特性ManimGL (3b1b)Manim社区版
导入语句
from manimlib import *
from manim import *
CLI命令
manimgl
manim
数学文本
Tex(R"\pi")
MathTex(r"\pi")
场景类
InteractiveScene
Scene
创建动画
ShowCreation
Create
相机
self.frame
self.camera.frame
固定到帧
mob.fix_in_frame()
self.add_fixed_in_frame_mobjects(mob)
包名称
manimgl
(PyPI)
manim
(PyPI)

Interactive Development Workflow

交互式开发工作流

ManimGL's killer feature is interactive development:
bash
undefined
ManimGL的核心特性是交互式开发:
bash
undefined

Start at line 20 with state preserved

从第20行开始,保留状态

manimgl scene.py MyScene -se 20

In interactive mode:
```python
manimgl scene.py MyScene -se 20

在交互模式中:
```python

Copy code to clipboard, then run:

复制代码到剪贴板,然后运行:

checkpoint_paste() # Run with animations checkpoint_paste(skip=True) # Run instantly (no animations) checkpoint_paste(record=True) # Record while running
undefined
checkpoint_paste() # 带动画运行 checkpoint_paste(skip=True) # 立即运行(无动画) checkpoint_paste(record=True) # 运行时录制
undefined

Camera Control (self.frame)

相机控制(self.frame)

python
undefined
python
undefined

Get the camera frame

获取相机帧

frame = self.frame
frame = self.frame

Reorient in 3D (phi, theta, gamma, center, height)

3D重定向(phi, theta, gamma, center, height)

frame.reorient(45, -30, 0, ORIGIN, 8)
frame.reorient(45, -30, 0, ORIGIN, 8)

Animate camera movement

动画相机移动

self.play(frame.animate.reorient(60, -45, 0))
self.play(frame.animate.reorient(60, -45, 0))

Fix mobjects to stay in screen space during 3D movement

固定mobjects在屏幕空间,不受3D移动影响

title.fix_in_frame()
undefined
title.fix_in_frame()
undefined

LaTeX with Tex class

使用Tex类的LaTeX

python
undefined
python
undefined

Use raw strings with capital R

使用大写R的原始字符串

formula = Tex(R"\int_0^1 x^2 , dx = \frac{1}{3}")
formula = Tex(R"\int_0^1 x^2 , dx = \frac{1}{3}")

Color mapping with t2c

使用t2c进行颜色映射

equation = Tex( R"E = mc^2", t2c={"E": BLUE, "m": GREEN, "c": YELLOW} )
equation = Tex( R"E = mc^2", t2c={"E": BLUE, "m": GREEN, "c": YELLOW} )

Isolate substrings for animation

隔离子串用于动画

formula = Tex(R"\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}") formula.set_color_by_tex("n", BLUE)
undefined
formula = Tex(R"\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}") formula.set_color_by_tex("n", BLUE)
undefined

Common Patterns

常见模式

Embedding for debugging

嵌入调试

python
def construct(self):
    circle = Circle()
    self.play(ShowCreation(circle))
    self.embed()  # Drops into IPython shell here
python
def construct(self):
    circle = Circle()
    self.play(ShowCreation(circle))
    self.embed()  # 在此处进入IPython shell

Set floor plane for 3D

为3D场景设置地面平面

python
self.set_floor_plane("xz")  # Makes xy the viewing plane
python
self.set_floor_plane("xz")  # 将xy设为观察平面

Backstroke for text readability

文本背描边提升可读性

python
text = Text("Label")
text.set_backstroke(BLACK, 5)  # Black outline behind text
python
text = Text("Label")
text.set_backstroke(BLACK, 5)  # 文本背后的黑色轮廓

Installation

安装

bash
undefined
bash
undefined

Install ManimGL

安装ManimGL

pip install manimgl
pip install manimgl

Check installation

检查安装

manimgl --version
undefined
manimgl --version
undefined

Common Pitfalls to Avoid

常见误区

  1. Version confusion - Ensure you're using
    manimgl
    , not
    manim
    (community version)
  2. ShowCreation vs Create - ManimGL uses
    ShowCreation
    , not
    Create
  3. Tex vs MathTex - ManimGL uses
    Tex
    with capital R raw strings
  4. self.frame vs self.camera.frame - ManimGL uses
    self.frame
    directly
  5. fix_in_frame() - Call on the mobject, not the scene
  6. Interactive mode - Use
    -se
    flag for interactive development
  1. 版本混淆 - 确保使用的是
    manimgl
    ,而非
    manim
    (社区版)
  2. ShowCreation与Create - ManimGL使用
    ShowCreation
    ,而非
    Create
  3. Tex与MathTex - ManimGL使用带大写R原始字符串的
    Tex
  4. self.frame与self.camera.frame - ManimGL直接使用
    self.frame
  5. fix_in_frame() - 在mobject上调用,而非场景
  6. 交互模式 - 使用-se参数进入交互式开发

License & Attribution

许可证与署名

This skill contains example code adapted from 3Blue1Brown's video repository by Grant Sanderson.
  • Attribution required - Credit both 3Blue1Brown and the adapter
  • NonCommercial - Not for commercial use
  • ShareAlike - Derivatives must use the same license
See LICENSE.txt for full details.
本内容包含改编自3Blue1Brown视频仓库的示例代码,原作者为Grant Sanderson。
许可证: CC BY-NC-SA 4.0
  • 需要署名 - 需同时注明3Blue1Brown和改编者
  • 非商业用途 - 不得用于商业用途
  • 相同方式共享 - 衍生作品必须使用相同许可证
详情请见LICENSE.txt