Skip to content
Track 07 · Guide

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.

Beginner@shine19048 min read

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:

bash
npx skills add adithya-s-k/manim_skill

Xem video demo

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)

  1. Python 3.7+: bắt buộc
  2. FFmpeg: để mã hoá video
  3. LaTeX: để dàn trang công thức toán (TeX Live, MiKTeX hoặc MacTeX)

Cài FFmpeg

macOS:

bash
brew install ffmpeg

Ubuntu/Debian:

bash
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:

bash
brew install mactex

Ubuntu/Debian:

bash
sudo apt install texlive-full

Windows: cài MiKTeX từ https://miktex.org/download

Cài Manim Community Edition

bash
# 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

bash
# 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):

bash
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ị)

bash
# 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ặc checkpoint_paste()

Dùng repo này

Cấu trúc repo

code
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

python
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:

bash
manim -pql scene.py BasicExample
# -p: preview after rendering
# -q: quality (l=low, m=medium, h=high)

ManimGL

python
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:

bash
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

bash
# 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

bash
# 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ăngManim CommunityManimGL
Importfrom manim import *from manimlib import *
Lệnh CLImanimmanimgl
Class Scene gốcScene, MovingCameraSceneScene, InteractiveScene
Hoạt hình tạo hìnhCreate()ShowCreation()
Class văn bảnText(), MathTex()Text(), Tex()
Render 3DHạn chếHỗ trợ OpenGL đầy đủ
Chế độ tương tácKhôngCó (cờ -se, .embed())
Điều khiển cameraMovingCameraSceneself.camera.frame
Cấu hìnhPython configFile YAML
Hằng số màuGiống nhauGiố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/:

  1. scenes.md: cấu trúc và vòng đời của Scene
  2. animations.md: pattern hoạt hình cơ bản
  3. mobjects.md: tạo và thao tác đối tượng
  4. colors.md: hệ màu và định dạng
  5. 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/:

  1. scenes.md: các loại Scene và InteractiveScene
  2. animations.md: nền tảng về hoạt hình
  3. camera.md: di chuyển camera và định hướng 3D
  4. 3d.md: tạo và render đối tượng 3D
  5. 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

ManimGL

Chung

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 manim hoặc python -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 2 hoặ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 Community
    • from 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

Write another guide for this track