1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| from manim import * class RendererChoiceDemo(Scene): """--renderer cairo / opengl:两种渲染后端的分工""" def construct(self): title = Text("--renderer 选哪个:cairo 还是 opengl", font_size=31).to_edge(UP, buff=0.4) self.play(Write(title)) def panel(name, flag, rows, color): head = Text(name, font_size=25, color=color) sub = Text(flag, font="Consolas", font_size=19, color=GREY_B) body = VGroup(*[Text(r, font_size=19, color=WHITE) for r in rows]) body.arrange(DOWN, buff=0.14, aligned_edge=LEFT) inner = VGroup(head, sub, body).arrange(DOWN, buff=0.18, aligned_edge=LEFT) box = RoundedRectangle(corner_radius=0.12, width=5.7, height=inner.height + 0.7, stroke_color=color, stroke_width=2, fill_color=color, fill_opacity=0.08) inner.move_to(box.get_center()) return VGroup(box, inner) left = panel("cairo(默认)", "--renderer cairo", ["CPU 逐帧渲染,稳定性最好", "支持全部 Manim 特性", "输出 mp4 / png,适合成片", "缺点:不能实时预览"], BLUE_B) right = panel("opengl", "--renderer opengl", ["GPU 实时绘制,可开交互窗口", "拖动视角、边看边调", "适合 3D 场景与调试", "缺点:部分特性尚未支持"], GREEN_B) cards = VGroup(left, right).arrange(RIGHT, buff=0.6).next_to(title, DOWN, buff=0.55) self.play(FadeIn(left, shift=RIGHT * 0.3), run_time=0.9) self.play(FadeIn(right, shift=LEFT * 0.3), run_time=0.9) self.wait(0.5) code = Text("manim -qm demo.py MyScene --renderer opengl", font="Consolas", font_size=20, color=GREEN) code.next_to(cards, DOWN, buff=0.55) self.play(FadeIn(code, shift=UP * 0.2)) knob = Text("成片用 cairo,调 3D 用 opengl", font_size=21, color=YELLOW) knob.next_to(code, DOWN, buff=0.35) self.play(FadeIn(knob, shift=UP * 0.15)) self.wait(1.6)
|