from manim import * import numpy as np from numpy import array, pi, cos, sin run_time = 1 data = [[1, 2], [3, 4]] defdot(pos, **kwargs): return Dot(pos, **kwargs) classR015_00(Scene): defconstruct(self): sc = self self.play(*[FadeIn(_o) for _o in [Text('hello world')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [Text('你好,世界')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [Text('こんにちは世界')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [Text('Привет, мир')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [Text('مرحبا بالعالم', font='sans-serif')]], run_time=1.0) self.wait(0.5) self.wait(0.40)
运行效果:
1.2 段落文本
段落文本 Paragraph可以多行文本进行简单的排版:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from manim import * import numpy as np from numpy import array, pi, cos, sin run_time = 1 data = [[1, 2], [3, 4]] defdot(pos, **kwargs): return Dot(pos, **kwargs) classR015_01(Scene): defconstruct(self): sc = self paragraph = Paragraph(' 春晓\n', '春眠不觉晓', '处处闻啼鸟', '夜来风雨声', '花落知多少') self.play(FadeIn(paragraph), run_time=1.0) self.wait(1) self.wait(0.5) self.wait(3.10)
运行效果:
1.3 带标记文本
带标记的文本MarkupText类似HTML,可以像 word 那样提供一些标记文本的功能。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from manim import * import numpy as np from numpy import array, pi, cos, sin run_time = 1 data = [[1, 2], [3, 4]] defdot(pos, **kwargs): return Dot(pos, **kwargs) classR015_02(Scene): defconstruct(self): sc = self self.play(*[FadeIn(_o) for _o in [MarkupText('<b>bold</b> <i>斜体文字</i>')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [MarkupText('<u>下划线</u> <s>中划线</s>')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [MarkupText('<span underline="double">双下划线</span> <span underline="error">错误标记</span>')]], run_time=1.0) self.play(*[FadeIn(_o) for _o in [MarkupText('下标和上标:H<sub>2</sub>O H<sub>3</sub>O<sup>+</sup>')]], run_time=1.0) self.wait(0.5) self.wait(1.10)