关于 manimgl-best-practices
面向 ManimGL 用户的参考技能,涵盖场景构建、动画、渲染和交互式开发。示例及与 Manim Community 的对比帮助用户采用正确的 API 和命令。
主要功能
- 01场景与动画规则
- 02Tex、样式和摄像机指南
- 033D 与交互式开发主题
- 04经过测试的示例和场景模板
- 05命令行、配置与版本对比
适用场景
- 01构建 ManimGL 场景
- 02使用交互模式调试
- 03查阅 ManimGL 语法与命令
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ adithya-s-k/ manim_skill --skill manimgl-best-practices安装后在 Claude Code 中输入/manimgl-best-practices确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
examples/attention_arcs_animation.pyattention_pattern_dots.pyattention_scenes.pyattention_softmax_masking.pyautoregressive_flow.pybasic_multihead.pybloch_sphere_3d.pyblock_collision_basic.pyblocks_3d.pycollision_phase_space.pycomplex_s_plane.pycost_function.pycube_projection_3d.pydamped_solutions_splane.pydot_product_visualization.pydouble_slit_interference.pyeigenvalue_equations.pyeigenvector_flow_field.pyeigenvector_matrix_transformation.pyelastic_collision_vectors.pyembedding_matrix.pyequation_transforms.pyexponential_derivative.pyfibonacci_eigenvalues.pygradient_descent_basic.pyhexagon_cube_correspondence.pyintegration_visualization.pylaplace_integral.pylight_polarization.pylinear_regression.py详细介绍
使用方法
阅读各个规则文件,了解详细说明和代码示例:
核心概念
- rules/scenes.md - InteractiveScene、Scene 类型和 construct 方法
- rules/mobjects.md - Mobject 类型、VMobject、群组和定位
- rules/animations.md - Animation 类、播放动画和时序
创建与变换
- rules/creation-animations.md - ShowCreation、Write、FadeIn、DrawBorderThenFill
- rules/transform-animations.md - Transform、ReplacementTransform、TransformMatchingTex
- rules/animation-groups.md - LaggedStart、Succession、AnimationGroup
文本与数学
- rules/tex.md - Tex 类、原始字符串 R"..." 和 LaTeX 渲染
- rules/text.md - Text Mobject、字体和样式
- rules/t2c.md - 用于为数学表达式着色的 tex_to_color_map(t2c)
样式与外观
- rules/colors.md - 颜色常量、渐变、RGB、十六进制、GLSL 着色
- rules/styling.md - 填充、描边、不透明度、背描边、光泽、阴影
3D 与摄像机
- rules/3d.md - 3D 对象、曲面、Sphere、Torus、参数曲面、光照
- rules/camera.md - frame.reorient()、欧拉角、fix_in_frame()、摄像机动画
交互式开发
- rules/interactive.md - 使用
-se标志进行交互模式开发、checkpoint_paste() - rules/frame.md - self.frame、摄像机控制、reorient 和缩放
- rules/embedding.md - 使用 self.embed() 进行 IPython 调试、touch() 模式
配置与 CLI
- rules/cli.md - manimgl 命令、标志(-w、-o、-se、-l、-h)、渲染选项
- rules/config.md - custom_config.yml、目录、摄像机设置、质量预设
实用示例
展示常见模式的完整测试示例文件:
- examples/basic_animations.py - 基本形状、文本和动画
- examples/math_visualization.py - LaTeX 方程和数学内容
- examples/graph_plotting.py - 坐标轴、函数和绘图
- examples/3d_visualization.py - 带摄像机控制和曲面的 3D 场景
- examples/updater_patterns.py - 使用 updater 的动态动画
场景模板
复制并修改这些模板,以开始新项目:
- templates/basic_scene.py - 标准 2D 场景模板
- templates/interactive_scene.py - 使用 self.embed() 的 InteractiveScene
- templates/3d_scene.py - 使用 frame.reorient() 的 3D 场景
- templates/math_scene.py - 数学推导和方程
快速参考
基本场景结构
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)
渲染命令
# Render and preview
manimgl scene.py MyScene
# Interactive mode - drop into shell at line 15
manimgl scene.py MyScene -se 15
# Write to file
manimgl scene.py MyScene -w
# Low quality for testing
manimgl scene.py MyScene -l
与 ManimCE 的主要区别
| 特性 | ManimGL (3b1b) | Manim Community |
|---|---|---|
| 导入 | 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) |
交互式开发工作流
ManimGL 的杀手级功能是交互式开发:
# Start at line 20 with state preserved
manimgl scene.py MyScene -se 20
在交互模式下:
# 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
摄像机控制(self.frame)
# Get the camera frame
frame = self.frame
# Reorient in 3D (phi, theta, gamma, center, height)
frame.reorient(45, -30, 0, ORIGIN, 8)
# Animate camera movement
self.play(frame.animate.reorient(60, -45, 0))
# Fix mobjects to stay in screen space during 3D movement
title.fix_in_frame()
使用 Tex 类编写 LaTeX
# Use raw strings with capital R
formula = Tex(R"\int_0^1 x^2 \, dx = \frac{1}{3}")
# Color mapping with t2c
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)
常见模式
用于调试的嵌入
def construct(self):
circle = Circle()
self.play(ShowCreation(circle))
self.embed() # Drops into IPython shell here
为 3D 设置地面平面
self.set_floor_plane("xz") # Makes xy the viewing plane
提高文本可读性的背描边
text = Text("Label")
text.set_backstroke(BLACK, 5) # Black outline behind text
安装
# Install ManimGL
pip install manimgl
# Check installation
manimgl --version
需要避免的常见问题
- 版本混淆 - 请确保使用
manimgl,而不是manim(社区版本) - ShowCreation 与 Create - ManimGL 使用
ShowCreation,而不是Create - Tex 与 MathTex - ManimGL 使用
Tex,并搭配首字母大写的 R 原始字符串 - self.frame 与 self.camera.frame - ManimGL 直接使用
self.frame - fix_in_frame() - 在 mobject 上调用,而不是在场景上调用
- 交互模式 - 在交互式开发中使用
-se标志
许可与归属
此技能包含改编自 Grant Sanderson 的 3Blue1Brown 视频仓库 的示例代码。
许可: CC BY-NC-SA 4.0
- 必须注明出处 - 同时标明 3Blue1Brown 和改编者
- 非商业用途 - 不可用于商业用途
- 相同方式共享 - 衍生作品必须采用相同许可
完整详情请参阅 LICENSE.txt。
评论
支持 Markdown