manimgl-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHow 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 flag, checkpoint_paste()
-se - 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
undefinedbash
undefinedRender 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
undefinedmanimgl scene.py MyScene -l
undefinedKey Differences from ManimCE
与Manim社区版的主要区别
| Feature | ManimGL (3b1b) | Manim Community |
|---|---|---|
| Import | | |
| CLI | | |
| Math text | | |
| Scene | | |
| Create anim | | |
| Camera | | |
| Fix in frame | | |
| Package | | |
| 特性 | ManimGL (3b1b) | Manim社区版 |
|---|---|---|
| 导入语句 | | |
| CLI命令 | | |
| 数学文本 | | |
| 场景类 | | |
| 创建动画 | | |
| 相机 | | |
| 固定到帧 | | |
| 包名称 | | |
Interactive Development Workflow
交互式开发工作流
ManimGL's killer feature is interactive development:
bash
undefinedManimGL的核心特性是交互式开发:
bash
undefinedStart at line 20 with state preserved
从第20行开始,保留状态
manimgl scene.py MyScene -se 20
In interactive mode:
```pythonmanimgl scene.py MyScene -se 20
在交互模式中:
```pythonCopy 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
undefinedcheckpoint_paste() # 带动画运行
checkpoint_paste(skip=True) # 立即运行(无动画)
checkpoint_paste(record=True) # 运行时录制
undefinedCamera Control (self.frame)
相机控制(self.frame)
python
undefinedpython
undefinedGet 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()
undefinedtitle.fix_in_frame()
undefinedLaTeX with Tex class
使用Tex类的LaTeX
python
undefinedpython
undefinedUse 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)
undefinedformula = Tex(R"\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}")
formula.set_color_by_tex("n", BLUE)
undefinedCommon Patterns
常见模式
Embedding for debugging
嵌入调试
python
def construct(self):
circle = Circle()
self.play(ShowCreation(circle))
self.embed() # Drops into IPython shell herepython
def construct(self):
circle = Circle()
self.play(ShowCreation(circle))
self.embed() # 在此处进入IPython shellSet floor plane for 3D
为3D场景设置地面平面
python
self.set_floor_plane("xz") # Makes xy the viewing planepython
self.set_floor_plane("xz") # 将xy设为观察平面Backstroke for text readability
文本背描边提升可读性
python
text = Text("Label")
text.set_backstroke(BLACK, 5) # Black outline behind textpython
text = Text("Label")
text.set_backstroke(BLACK, 5) # 文本背后的黑色轮廓Installation
安装
bash
undefinedbash
undefinedInstall ManimGL
安装ManimGL
pip install manimgl
pip install manimgl
Check installation
检查安装
manimgl --version
undefinedmanimgl --version
undefinedCommon Pitfalls to Avoid
常见误区
- Version confusion - Ensure you're using , not
manimgl(community version)manim - ShowCreation vs Create - ManimGL uses , not
ShowCreationCreate - Tex vs MathTex - ManimGL uses with capital R raw strings
Tex - self.frame vs self.camera.frame - ManimGL uses directly
self.frame - fix_in_frame() - Call on the mobject, not the scene
- Interactive mode - Use flag for interactive development
-se
- 版本混淆 - 确保使用的是,而非
manimgl(社区版)manim - ShowCreation与Create - ManimGL使用,而非
ShowCreationCreate - Tex与MathTex - ManimGL使用带大写R原始字符串的
Tex - self.frame与self.camera.frame - ManimGL直接使用
self.frame - fix_in_frame() - 在mobject上调用,而非场景
- 交互模式 - 使用-se参数进入交互式开发
License & Attribution
许可证与署名
This skill contains example code adapted from 3Blue1Brown's video repository by Grant Sanderson.
License: CC BY-NC-SA 4.0
- 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。