manim-code-anim 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manim_code_anim-0.1.0/LICENSE +21 -0
- manim_code_anim-0.1.0/PKG-INFO +202 -0
- manim_code_anim-0.1.0/README.md +183 -0
- manim_code_anim-0.1.0/pyproject.toml +21 -0
- manim_code_anim-0.1.0/setup.cfg +4 -0
- manim_code_anim-0.1.0/src/manim_code_anim/__init__.py +0 -0
- manim_code_anim-0.1.0/src/manim_code_anim/code_anim.py +323 -0
- manim_code_anim-0.1.0/src/manim_code_anim/language_colors.py +1318 -0
- manim_code_anim-0.1.0/src/manim_code_anim.egg-info/PKG-INFO +202 -0
- manim_code_anim-0.1.0/src/manim_code_anim.egg-info/SOURCES.txt +12 -0
- manim_code_anim-0.1.0/src/manim_code_anim.egg-info/dependency_links.txt +1 -0
- manim_code_anim-0.1.0/src/manim_code_anim.egg-info/requires.txt +6 -0
- manim_code_anim-0.1.0/src/manim_code_anim.egg-info/top_level.txt +1 -0
- manim_code_anim-0.1.0/tests/test_code_anim.py +93 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wangyubin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: manim-code-anim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 代码输入动画效果
|
|
5
|
+
Author-email: databook <linuxr@aliyun.com>
|
|
6
|
+
Maintainer-email: databook <linuxr@aliyun.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/linuxr/manim-code-anim
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: build>=1.4.0
|
|
13
|
+
Requires-Dist: manim>=0.20.0
|
|
14
|
+
Requires-Dist: setuptools>=82.0.0
|
|
15
|
+
Requires-Dist: tokenize-all-code>=1.0.18
|
|
16
|
+
Requires-Dist: twine>=6.2.0
|
|
17
|
+
Requires-Dist: wheel>=0.46.3
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Manim Code Anim
|
|
21
|
+
|
|
22
|
+
代码输入动画效果,基于 Manim 库实现的代码块动画效果。
|
|
23
|
+
|
|
24
|
+
## 项目简介
|
|
25
|
+
|
|
26
|
+
`manim-code-anim` 是一个基于 Manim 的扩展库,用于在 Manim 动画中创建带有语法高亮的代码块动画。该库基于 [CasualCodersProjects/manim-code-blocks](https://github.com/CasualCodersProjects/manim-code-blocks) 库进行修改和扩展。
|
|
27
|
+
|
|
28
|
+
### 主要功能
|
|
29
|
+
|
|
30
|
+
- 支持多种编程语言的语法高亮
|
|
31
|
+
- 代码逐字显示动画效果
|
|
32
|
+
- 支持中文显示
|
|
33
|
+
- 可自定义字体和主题
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
### 依赖项
|
|
38
|
+
|
|
39
|
+
- Python 3.12+
|
|
40
|
+
- Manim 0.20.0+
|
|
41
|
+
- tokenize-all-code 1.0.18+
|
|
42
|
+
|
|
43
|
+
### 安装方法
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 克隆仓库
|
|
47
|
+
git clone https://github.com/yourusername/manim-code-anim.git
|
|
48
|
+
cd manim-code-anim
|
|
49
|
+
|
|
50
|
+
# 安装依赖
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 使用示例
|
|
55
|
+
|
|
56
|
+
### 基本使用
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from manim import *
|
|
60
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
61
|
+
|
|
62
|
+
class CodeAnimation(Scene):
|
|
63
|
+
def construct(self):
|
|
64
|
+
# 创建一个Python代码块
|
|
65
|
+
code = CodeAnim(
|
|
66
|
+
text='print("Hello World!")',
|
|
67
|
+
language=Python
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# 播放创建动画
|
|
71
|
+
self.play(*code.create())
|
|
72
|
+
self.wait(2)
|
|
73
|
+
|
|
74
|
+
# 播放销毁动画
|
|
75
|
+
self.play(*code.uncreate())
|
|
76
|
+
self.wait()
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
scene = CodeAnimation()
|
|
80
|
+
scene.render()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 多行代码
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from manim import *
|
|
87
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
88
|
+
|
|
89
|
+
class MultiLineCode(Scene):
|
|
90
|
+
def construct(self):
|
|
91
|
+
python_code = '''
|
|
92
|
+
def fibonacci(n):
|
|
93
|
+
if n <= 1:
|
|
94
|
+
return n
|
|
95
|
+
return fibonacci(n-1) + fibonacci(n-2)
|
|
96
|
+
|
|
97
|
+
print(fibonacci(10))
|
|
98
|
+
'''
|
|
99
|
+
|
|
100
|
+
code = CodeAnim(
|
|
101
|
+
text=python_code,
|
|
102
|
+
language=Python
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
self.play(*code.create())
|
|
106
|
+
self.wait(3)
|
|
107
|
+
self.play(*code.uncreate())
|
|
108
|
+
self.wait()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 支持中文
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from manim import *
|
|
115
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
116
|
+
|
|
117
|
+
class ChineseCode(Scene):
|
|
118
|
+
def construct(self):
|
|
119
|
+
code = CodeAnim(
|
|
120
|
+
text='''
|
|
121
|
+
# 这是中文注释
|
|
122
|
+
print("你好,世界!") # 中文注释
|
|
123
|
+
''',
|
|
124
|
+
language=Python
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
self.play(*code.create())
|
|
128
|
+
self.wait(2)
|
|
129
|
+
self.play(*code.uncreate())
|
|
130
|
+
self.wait()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 自定义字体
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from manim import *
|
|
137
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
138
|
+
|
|
139
|
+
class CustomFontCode(Scene):
|
|
140
|
+
def construct(self):
|
|
141
|
+
code = CodeAnim(
|
|
142
|
+
text='print("Hello, 世界!")',
|
|
143
|
+
language=Python,
|
|
144
|
+
font="Courier New", # 英文代码字体
|
|
145
|
+
chinese_font="SimHei" # 中文字体
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
self.play(*code.create())
|
|
149
|
+
self.wait(2)
|
|
150
|
+
self.play(*code.uncreate())
|
|
151
|
+
self.wait()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 支持的编程语言
|
|
155
|
+
|
|
156
|
+
- C
|
|
157
|
+
- C++
|
|
158
|
+
- C#
|
|
159
|
+
- Fortran
|
|
160
|
+
- Go
|
|
161
|
+
- Haskell
|
|
162
|
+
- Java
|
|
163
|
+
- JavaScript
|
|
164
|
+
- Lua
|
|
165
|
+
- Python
|
|
166
|
+
- Ruby
|
|
167
|
+
- Rust
|
|
168
|
+
- SQL
|
|
169
|
+
- TypeScript
|
|
170
|
+
|
|
171
|
+
## API 参考
|
|
172
|
+
|
|
173
|
+
### CodeAnim 类
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
CodeAnim(
|
|
177
|
+
text: str, # 要显示的代码文本
|
|
178
|
+
language: ProgrammingLanguage | None = None, # 编程语言
|
|
179
|
+
theme: Theme = OneDark, # 语法高亮主题
|
|
180
|
+
font: str = "FiraCode Nerd Font Mono", # 英文代码字体
|
|
181
|
+
chinese_font: str = "Microsoft YaHei", # 中文字体
|
|
182
|
+
**kwargs: object # 传递给VGroup的其他参数
|
|
183
|
+
)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 方法
|
|
187
|
+
|
|
188
|
+
- `create(**kwargs)`: 返回创建代码块的动画元组
|
|
189
|
+
- `uncreate(**kwargs)`: 返回销毁代码块的动画元组
|
|
190
|
+
|
|
191
|
+
## 基于的库
|
|
192
|
+
|
|
193
|
+
本项目基于 [CasualCodersProjects/manim-code-blocks](https://github.com/CasualCodersProjects/manim-code-blocks) 库,进行了以下修改:
|
|
194
|
+
|
|
195
|
+
- 添加了中文支持
|
|
196
|
+
- 优化了字体处理
|
|
197
|
+
- 修复了一些bug
|
|
198
|
+
- 完善了文档
|
|
199
|
+
|
|
200
|
+
## 许可证
|
|
201
|
+
|
|
202
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Manim Code Anim
|
|
2
|
+
|
|
3
|
+
代码输入动画效果,基于 Manim 库实现的代码块动画效果。
|
|
4
|
+
|
|
5
|
+
## 项目简介
|
|
6
|
+
|
|
7
|
+
`manim-code-anim` 是一个基于 Manim 的扩展库,用于在 Manim 动画中创建带有语法高亮的代码块动画。该库基于 [CasualCodersProjects/manim-code-blocks](https://github.com/CasualCodersProjects/manim-code-blocks) 库进行修改和扩展。
|
|
8
|
+
|
|
9
|
+
### 主要功能
|
|
10
|
+
|
|
11
|
+
- 支持多种编程语言的语法高亮
|
|
12
|
+
- 代码逐字显示动画效果
|
|
13
|
+
- 支持中文显示
|
|
14
|
+
- 可自定义字体和主题
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
### 依赖项
|
|
19
|
+
|
|
20
|
+
- Python 3.12+
|
|
21
|
+
- Manim 0.20.0+
|
|
22
|
+
- tokenize-all-code 1.0.18+
|
|
23
|
+
|
|
24
|
+
### 安装方法
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 克隆仓库
|
|
28
|
+
git clone https://github.com/yourusername/manim-code-anim.git
|
|
29
|
+
cd manim-code-anim
|
|
30
|
+
|
|
31
|
+
# 安装依赖
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 使用示例
|
|
36
|
+
|
|
37
|
+
### 基本使用
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from manim import *
|
|
41
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
42
|
+
|
|
43
|
+
class CodeAnimation(Scene):
|
|
44
|
+
def construct(self):
|
|
45
|
+
# 创建一个Python代码块
|
|
46
|
+
code = CodeAnim(
|
|
47
|
+
text='print("Hello World!")',
|
|
48
|
+
language=Python
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# 播放创建动画
|
|
52
|
+
self.play(*code.create())
|
|
53
|
+
self.wait(2)
|
|
54
|
+
|
|
55
|
+
# 播放销毁动画
|
|
56
|
+
self.play(*code.uncreate())
|
|
57
|
+
self.wait()
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
scene = CodeAnimation()
|
|
61
|
+
scene.render()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 多行代码
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from manim import *
|
|
68
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
69
|
+
|
|
70
|
+
class MultiLineCode(Scene):
|
|
71
|
+
def construct(self):
|
|
72
|
+
python_code = '''
|
|
73
|
+
def fibonacci(n):
|
|
74
|
+
if n <= 1:
|
|
75
|
+
return n
|
|
76
|
+
return fibonacci(n-1) + fibonacci(n-2)
|
|
77
|
+
|
|
78
|
+
print(fibonacci(10))
|
|
79
|
+
'''
|
|
80
|
+
|
|
81
|
+
code = CodeAnim(
|
|
82
|
+
text=python_code,
|
|
83
|
+
language=Python
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
self.play(*code.create())
|
|
87
|
+
self.wait(3)
|
|
88
|
+
self.play(*code.uncreate())
|
|
89
|
+
self.wait()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 支持中文
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from manim import *
|
|
96
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
97
|
+
|
|
98
|
+
class ChineseCode(Scene):
|
|
99
|
+
def construct(self):
|
|
100
|
+
code = CodeAnim(
|
|
101
|
+
text='''
|
|
102
|
+
# 这是中文注释
|
|
103
|
+
print("你好,世界!") # 中文注释
|
|
104
|
+
''',
|
|
105
|
+
language=Python
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
self.play(*code.create())
|
|
109
|
+
self.wait(2)
|
|
110
|
+
self.play(*code.uncreate())
|
|
111
|
+
self.wait()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 自定义字体
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from manim import *
|
|
118
|
+
from manim_code_anim.code_anim import CodeAnim, Python
|
|
119
|
+
|
|
120
|
+
class CustomFontCode(Scene):
|
|
121
|
+
def construct(self):
|
|
122
|
+
code = CodeAnim(
|
|
123
|
+
text='print("Hello, 世界!")',
|
|
124
|
+
language=Python,
|
|
125
|
+
font="Courier New", # 英文代码字体
|
|
126
|
+
chinese_font="SimHei" # 中文字体
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
self.play(*code.create())
|
|
130
|
+
self.wait(2)
|
|
131
|
+
self.play(*code.uncreate())
|
|
132
|
+
self.wait()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 支持的编程语言
|
|
136
|
+
|
|
137
|
+
- C
|
|
138
|
+
- C++
|
|
139
|
+
- C#
|
|
140
|
+
- Fortran
|
|
141
|
+
- Go
|
|
142
|
+
- Haskell
|
|
143
|
+
- Java
|
|
144
|
+
- JavaScript
|
|
145
|
+
- Lua
|
|
146
|
+
- Python
|
|
147
|
+
- Ruby
|
|
148
|
+
- Rust
|
|
149
|
+
- SQL
|
|
150
|
+
- TypeScript
|
|
151
|
+
|
|
152
|
+
## API 参考
|
|
153
|
+
|
|
154
|
+
### CodeAnim 类
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
CodeAnim(
|
|
158
|
+
text: str, # 要显示的代码文本
|
|
159
|
+
language: ProgrammingLanguage | None = None, # 编程语言
|
|
160
|
+
theme: Theme = OneDark, # 语法高亮主题
|
|
161
|
+
font: str = "FiraCode Nerd Font Mono", # 英文代码字体
|
|
162
|
+
chinese_font: str = "Microsoft YaHei", # 中文字体
|
|
163
|
+
**kwargs: object # 传递给VGroup的其他参数
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 方法
|
|
168
|
+
|
|
169
|
+
- `create(**kwargs)`: 返回创建代码块的动画元组
|
|
170
|
+
- `uncreate(**kwargs)`: 返回销毁代码块的动画元组
|
|
171
|
+
|
|
172
|
+
## 基于的库
|
|
173
|
+
|
|
174
|
+
本项目基于 [CasualCodersProjects/manim-code-blocks](https://github.com/CasualCodersProjects/manim-code-blocks) 库,进行了以下修改:
|
|
175
|
+
|
|
176
|
+
- 添加了中文支持
|
|
177
|
+
- 优化了字体处理
|
|
178
|
+
- 修复了一些bug
|
|
179
|
+
- 完善了文档
|
|
180
|
+
|
|
181
|
+
## 许可证
|
|
182
|
+
|
|
183
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "manim-code-anim"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "代码输入动画效果"
|
|
5
|
+
authors = [{ name = "databook", email = "linuxr@aliyun.com" }]
|
|
6
|
+
maintainers = [{ name = "databook", email = "linuxr@aliyun.com" }]
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"build>=1.4.0",
|
|
12
|
+
"manim>=0.20.0",
|
|
13
|
+
"setuptools>=82.0.0",
|
|
14
|
+
"tokenize-all-code>=1.0.18",
|
|
15
|
+
"twine>=6.2.0",
|
|
16
|
+
"wheel>=0.46.3",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/linuxr/manim-code-anim"
|
|
File without changes
|