前言
本篇文章主要介绍manim中文本文字,数学公式以及物体的移动几个问题
一、文本文字
1.文字
需要用到Text( ‘ ’)
from manim import*
class example(Scene):
def construct(self):
ex = Text('我爱MANIM')
self.play(Write(ex))
self.wait(1)
2.文本文字属性
BackgroundRectangle | 背景色 |
set_color_by_gradient | 渐变色 |
item.align_to | 使文字对齐 |
font | 字体 |
font_size | 字号 |
weight | 粗体 |
alant | 斜体 |
t2f | 按字符设置字体 |
t2s | 按字符设置斜体 |
t2w | 按字符设置粗体 |
3.段落文本
使用Paragraph可以对文字进行简单的排版
from manim import*
class example(Scene):
def construct(self):
ex = Paragraph(
" 百家讲坛\n",
"\t\t——易中天\n",
"前途光明我看不见",
"道路曲折我走不完",
)
self.play(Write(ex))
self.wait(1)
4. 标记文本
from manim import*
class example(Scene):
def construct(self):
ex = MarkupText("<b>A</b> <i>B</i> <u>C</u> <s>D</s>" )
self.play(Write(ex))
self.wait(1)
<b> </b> | 粗体 |
<i> </i> | 斜体 |
<u> </u> | 下划线 |
<s> </s> | 中划线 |
5.标题
from manim import*
class example(Scene):
def construct(self):
ex = Title('manim')
self.play(Write(ex))
self.wait(1)
二、数学公式
请下载并安装MikText或者TexLive,在https://blog.csdn.net/2401_82621879/article/details/136488684?spm=1001.2014.3001.5501 这篇文章中有详细介绍latex的用法
三、移动
from manim import*
class example(Scene):
def construct(self):
ex = Circle()
ex.to_edge(UP,buff = 0.5)
self.play(Write(ex))
self.wait(1)
UP可替换为其他方位,方位间也可以利用线性组合表出,buff = i,其中i指到边界的距离
move_to也可以移动
from manim import*
class example(Scene):
def construct(self):
ex = Circle()
ex.move_to(3*DOWN)
self.play(Write(ex))
self.wait(1)
其中i*DOWN中i为移动的距离,DOWN为方位可以替换。
from manim import*
class example(Scene):
def construct(self):
m = Circle ()
ex = Circle()
ex.next_to(m,UP,buff = 0.5)
self.play(Write(m))
self.play(Write(ex))
self.wait(1)
next_to可以将一个物体移动到零一物体周围,括号中第一个元素为想要移动到的物体的名字,第二个元素为移动的方位,第三个元素为具体物体的距离
四、放大缩小
from manim import*
class example(Scene):
def construct(self):
m = Circle ()
ex = Circle()
ex.scale(2)
self.play(Write(m))
self.play(Write(ex))
self.wait(1)
scale后括号内为改变大小的数值
五、 旋转
from manim import*
class example(Scene):
def construct(self):
m = Circle()
ex = Circle()
ex.rotate(angle = PI/2,axis = OUT,about_point = np.array([1, 1, 0]))
self.play(Write(ex))
self.play(Write(m))
self.wait(1)
angle为旋转的角度,axis控制顺时针或逆时针旋转,about_point为绕着旋转的点