Manim入门教程(2)

前言

本篇文章主要介绍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为绕着旋转的点

  • 14
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值