You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

5 months ago
from manim import *
import pygments # 确保已安装pygments
class CodeDemo(Scene):
def construct(self):
# 使用Text显示代码兼容性最佳方案
code_content = '''from manim import *
class FadeInSquare(Scene):
def construct(self):
s = Square()
self.play(FadeIn(s))
self.play(s.animate.scale(2))
self.wait()
'''
# 创建代码文本对象
code_text = Text(
code_content,
font="Monospace",
line_spacing=0.6,
font_size=20,
color=WHITE
).scale(0.7)
# 添加背景框
frame = SurroundingRectangle(code_text, color=BLUE, buff=0.5)
# 动画序列
self.play(Create(frame), run_time=1)
self.play(Write(code_text), run_time=3)
self.wait(2)
self.play(FadeOut(code_text), FadeOut(frame))
if __name__ == '__main__':
config = {
"quality": "low_quality",
"preview": True,
"media_dir": "./output"
}
with tempconfig(config):
scene = CodeDemo()
scene.render()