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.

34 lines
924 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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