mcpField
M
manimgl-best-practices

manimgl-best-practices

github.com/adithya-s-k创意与媒体1.2k2.2k 次安装40 周前更新
代码仓库

关于 manimgl-best-practices

面向 ManimGL 用户的参考技能,涵盖场景构建、动画、渲染和交互式开发。示例及与 Manim Community 的对比帮助用户采用正确的 API 和命令。

主要功能

  1. 01场景与动画规则
  2. 02Tex、样式和摄像机指南
  3. 033D 与交互式开发主题
  4. 04经过测试的示例和场景模板
  5. 05命令行、配置与版本对比

适用场景

  1. 01构建 ManimGL 场景
  2. 02使用交互模式调试
  3. 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.py
attention_pattern_dots.py
attention_scenes.py
attention_softmax_masking.py
autoregressive_flow.py
basic_multihead.py
bloch_sphere_3d.py
block_collision_basic.py
blocks_3d.py
collision_phase_space.py
complex_s_plane.py
cost_function.py
cube_projection_3d.py
damped_solutions_splane.py
dot_product_visualization.py
double_slit_interference.py
eigenvalue_equations.py
eigenvector_flow_field.py
eigenvector_matrix_transformation.py
elastic_collision_vectors.py
embedding_matrix.py
equation_transforms.py
exponential_derivative.py
fibonacci_eigenvalues.py
gradient_descent_basic.py
hexagon_cube_correspondence.py
integration_visualization.py
laplace_integral.py
light_polarization.py
linear_regression.py

详细介绍

使用方法

阅读各个规则文件,了解详细说明和代码示例:

核心概念
创建与变换
文本与数学
  • 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()、摄像机动画
交互式开发
配置与 CLI
  • rules/cli.md - manimgl 命令、标志(-w、-o、-se、-l、-h)、渲染选项
  • rules/config.md - custom_config.yml、目录、摄像机设置、质量预设

实用示例

展示常见模式的完整测试示例文件:

场景模板

复制并修改这些模板,以开始新项目:

快速参考

基本场景结构
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 *
CLImanimglmanim
数学文本Tex(R"\pi")MathTex(r"\pi")
场景InteractiveSceneScene
创建动画ShowCreationCreate
摄像机self.frameself.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
需要避免的常见问题
  1. 版本混淆 - 请确保使用 manimgl,而不是 manim(社区版本)
  2. ShowCreation 与 Create - ManimGL 使用 ShowCreation,而不是 Create
  3. Tex 与 MathTex - ManimGL 使用 Tex,并搭配首字母大写的 R 原始字符串
  4. self.frame 与 self.camera.frame - ManimGL 直接使用 self.frame
  5. fix_in_frame() - 在 mobject 上调用,而不是在场景上调用
  6. 交互模式 - 在交互式开发中使用 -se 标志

许可与归属

此技能包含改编自 Grant Sanderson 的 3Blue1Brown 视频仓库 的示例代码。

许可: CC BY-NC-SA 4.0

  • 必须注明出处 - 同时标明 3Blue1Brown 和改编者
  • 非商业用途 - 不可用于商业用途
  • 相同方式共享 - 衍生作品必须采用相同许可

完整详情请参阅 LICENSE.txt。

评论

支持 Markdown