Files
dsProject/dsLightRag/Manim/L9_CodeDemo.py
2025-08-14 15:45:08 +08:00

34 lines
924 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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