Làm hoạt hình toán học với Manim skill cho agent
Cài Manim Community Edition hoặc ManimGL cùng hai skill best practice để agent viết code hoạt hình toán học đúng cho từng phiên bản.
This content is currently available in Vietnamese only.
Bài này giới thiệu repo Manim Skills, cách cài Manim và hai skill best practice để agent lập trình viết code hoạt hình toán học chính xác.
Repo là bộ sưu tập best practice, pattern và ví dụ cho cả Manim Community Edition và ManimGL (phiên bản của 3Blue1Brown), gồm các ví dụ code đã được kiểm thử và hướng dẫn để tạo hoạt hình toán học.
Bắt đầu nhanh: thêm cả hai skill Manim vào AI agent của bạn:
npx skills add adithya-s-k/manim_skill
Hai phiên bản Manim
Manim Community Edition (manim)
- Repository: https://github.com/ManimCommunity/manim
- Trọng tâm: do cộng đồng duy trì, ổn định, tài liệu đầy đủ
- Phù hợp cho: dùng trong sản xuất, nội dung giáo dục, dự án cộng tác
- Lệnh: CLI
manim - Import:
from manim import *
ManimGL (manimgl)
- Repository: https://github.com/3b1b/manim
- Trọng tâm: phiên bản gốc của Grant Sanderson (3Blue1Brown), render bằng OpenGL
- Phù hợp cho: phát triển tương tác, cảnh 3D, làm prototype nhanh
- Lệnh: CLI
manimgl - Import:
from manimlib import *
Cài đặt
Yêu cầu chung (cả hai phiên bản)
- Python 3.7+: bắt buộc
- FFmpeg: để mã hoá video
- LaTeX: để dàn trang công thức toán (TeX Live, MiKTeX hoặc MacTeX)
Cài FFmpeg
macOS:
brew install ffmpeg
Ubuntu/Debian:
sudo apt update
sudo apt install ffmpeg
Windows: tải từ https://ffmpeg.org/download.html và thêm vào PATH.
Cài LaTeX
macOS:
brew install mactex
Ubuntu/Debian:
sudo apt install texlive-full
Windows: cài MiKTeX từ https://miktex.org/download
Cài Manim Community Edition
# Using pip
pip install manim
# Using uv (recommended for this project)
uv pip install manim
# Verify installation
manim --version
Tài liệu: https://docs.manim.community/
Cài ManimGL
# Using pip
pip install manimgl
# Using uv (recommended for this project)
uv pip install manimgl
# Verify installation
manimgl --version
Yêu cầu thêm trên macOS (ARM):
arch -arm64 brew install pkg-config cairo
Tích hợp Skills.sh
Repo cung cấp hai AI Agent Skill, cài được bằng một lệnh qua skills.sh.
Cài bằng npx (khuyến nghị)
# Install Manim Community Edition best practices
npx skills add adithya-s-k/manim_skill/skills/manimce-best-practices
# Install ManimGL best practices
npx skills add adithya-s-k/manim_skill/skills/manimgl-best-practices
# Or install both
npx skills add adithya-s-k/manim_skill/skills/manimce-best-practices adithya-s-k/manim_skill/skills/manimgl-best-practices
Skill là gì?
Skill là khả năng (capability) dùng lại được cho agent lập trình. Sau khi cài, trợ lý AI của bạn (như Claude, GitHub Copilot hay Cursor) tự động có:
- Best practice theo lĩnh vực
- Ví dụ code chạy được
- Pattern thường dùng và anti-pattern
- Kiến thức riêng của framework
Các skill tuân theo chuẩn mở Agent Skills và chạy được trên nhiều công cụ AI.
Khi nào skill được kích hoạt
manimce-best-practices tự nạp khi:
- Bạn import
from manim import * - Bạn dùng lệnh CLI
manim - Bạn làm việc với class Scene, hoạt hình toán học hoặc render LaTeX
- Bạn tạo video giáo dục hoặc giải thích trực quan bằng Manim Community
manimgl-best-practices tự nạp khi:
- Bạn import
from manimlib import * - Bạn dùng lệnh CLI
manimgl - Bạn làm việc với InteractiveScene, render 3D hoặc điều khiển camera frame
- Bạn dùng chế độ tương tác với
.embed()hoặccheckpoint_paste()
Dùng repo này
Cấu trúc repo
manim_skill/
├── skills/
│ ├── manimce-best-practices/ # Manim Community Edition skills
│ │ ├── SKILL.md # Skill metadata
│ │ └── rules/ # Individual best practice guides
│ │ ├── animations.md
│ │ ├── scenes.md
│ │ ├── mobjects.md
│ │ └── ...
│ │
│ └── manimgl-best-practices/ # ManimGL skills
│ ├── SKILL.md
│ └── rules/
│ ├── animations.md
│ ├── 3d.md
│ ├── camera.md
│ └── ...
│
└── tests/
├── manimce/ # Tests for Community Edition
└── manimgl/ # Tests for ManimGL
Mỗi file skill có gì?
Mỗi file .md gồm:
- Best practice cho từng tính năng cụ thể của Manim
- Ví dụ code chạy được (đều đã kiểm thử)
- Pattern thường dùng và tình huống sử dụng
- Cạm bẫy cần tránh
- Khác biệt API giữa hai phiên bản
Ví dụ bắt đầu nhanh
Manim Community Edition
from manim import *
class BasicExample(Scene):
def construct(self):
circle = Circle()
circle.set_fill(BLUE, opacity=0.5)
circle.set_stroke(BLUE_E, width=4)
self.play(Create(circle))
self.wait()
Chạy:
manim -pql scene.py BasicExample
# -p: preview after rendering
# -q: quality (l=low, m=medium, h=high)
ManimGL
from manimlib import *
class BasicExample(InteractiveScene):
def construct(self):
circle = Circle()
circle.set_fill(BLUE, opacity=0.5)
circle.set_stroke(BLUE_E, width=4)
self.play(ShowCreation(circle))
self.wait()
Chạy:
manimgl scene.py BasicExample --write_file
# --write_file: save video output
# -s: skip to last frame
# -w: write file without opening
Chạy test
Repo có bộ test đầy đủ để đảm bảo mọi ví dụ code chạy đúng.
Test skill Manim Community Edition
# Test all files
uv run python tests/manimce/test_all_skills.py
# Test specific file
uv run python tests/manimce/test_all_skills.py animations.md
# Run with multiple workers (faster)
uv run python tests/manimce/test_all_skills.py -j 4
Test skill ManimGL
# Test all files
uv run python tests/manimgl/test_all_skills.py
# Test specific file
uv run python tests/manimgl/test_all_skills.py 3d.md
# Run with multiple workers (use caution - can cause OOM)
uv run python tests/manimgl/test_all_skills.py -j 4
Khác biệt chính giữa hai phiên bản
| Tính năng | Manim Community | ManimGL |
|---|---|---|
| Import | from manim import * | from manimlib import * |
| Lệnh CLI | manim | manimgl |
| Class Scene gốc | Scene, MovingCameraScene | Scene, InteractiveScene |
| Hoạt hình tạo hình | Create() | ShowCreation() |
| Class văn bản | Text(), MathTex() | Text(), Tex() |
| Render 3D | Hạn chế | Hỗ trợ OpenGL đầy đủ |
| Chế độ tương tác | Không | Có (cờ -se, .embed()) |
| Điều khiển camera | MovingCameraScene | self.camera.frame |
| Cấu hình | Python config | File YAML |
| Hằng số màu | Giống nhau | Giống nhau + biến thể (ví dụ BLUE_A, BLUE_E) |
Khám phá các skill
Với Manim Community Edition
Bắt đầu với các hướng dẫn trong skills/manimce-best-practices/rules/:
- scenes.md: cấu trúc và vòng đời của Scene
- animations.md: pattern hoạt hình cơ bản
- mobjects.md: tạo và thao tác đối tượng
- colors.md: hệ màu và định dạng
- text.md: render văn bản và LaTeX
Với ManimGL
Bắt đầu với các hướng dẫn trong skills/manimgl-best-practices/rules/:
- scenes.md: các loại Scene và InteractiveScene
- animations.md: nền tảng về hoạt hình
- camera.md: di chuyển camera và định hướng 3D
- 3d.md: tạo và render đối tượng 3D
- interactive.md: quy trình (workflow) phát triển tương tác
Giấy phép
Repo dùng giấy phép MIT, xem file LICENSE.
Lưu ý: giấy phép này áp dụng cho tài liệu học và ví dụ code trong repo. Các framework Manim bên dưới (Manim Community Edition và ManimGL) có giấy phép riêng.
Tài nguyên
Manim Community Edition
- Tài liệu: https://docs.manim.community/
- Discord: https://www.manim.community/discord/
- GitHub: https://github.com/ManimCommunity/manim
ManimGL
- Tài liệu: https://3b1b.github.io/manim/
- GitHub: https://github.com/3b1b/manim
- Video hướng dẫn: kênh YouTube của Grant
Chung
- 3Blue1Brown: https://www.youtube.com/@3blue1brown
- Manim Community: https://www.manim.community/
Xử lý sự cố
"Command not found: manim/manimgl"
- Kiểm tra bản cài:
pip list | grep manim - Kiểm tra cấu hình PATH
- Thử:
python -m manimhoặcpython -m manimlib
Lỗi LaTeX
- Cài bản phân phối LaTeX đầy đủ (không phải bản cơ bản)
- ManimCE: thử
manim --tex_template <template>với các template khác nhau - ManimGL: kiểm tra
custom_defaults.ymlđể xem cấu hình LaTeX
Video không phát được
- Cài codec media cho hệ điều hành
- Thử các mức chất lượng khác (
-ql,-qm,-qh) - Kiểm tra bản cài FFmpeg:
ffmpeg -version
Hết bộ nhớ (khi test song song)
- Giảm số worker:
-j 2hoặc-j 4 - Test từng file
- Đóng các ứng dụng khác
Lỗi import / sai phiên bản
- Kiểm tra bạn import đúng phiên bản:
from manim import *→ Manim Communityfrom manimlib import *→ ManimGL
- Gỡ các bản xung đột:
pip uninstall manim manimgl manimlib - Cài lại phiên bản bạn cần
Nguồn
- Dịch và biên tập từ https://raw.githubusercontent.com/adithya-s-k/manim_skill/main/README.md, giấy phép MIT.