Manim入门教程(1)

前言

    想要成功的做出美妙的数学动画,做一些基础性的学习是必要,接下来让我们从最基本的图形开始我们的学习。

一、属性

1.共有属性

属性备注
color颜色,默认为白色
opacity透明度,默认为0
gloss反光度
shadow阴影

2.图形属性

属性备注
fill_color填充的颜色
fill_opacity

填充的透明度

stroke_color轮廓线的颜色
stroke_opacity轮廓线的透明度
stroke_width轮廓线的粗细
draw_stroke_behind_fill是否在填充后在绘制轮廓线

background_image_fill

图形填充图片的路径

二、点

点是其他图形的基础,你可以选择用点为其他图形定位,这里的点可以是三维点[x,y,z]。也可以是二维点,如果绘制二维点只需要将z坐标令为0,即[x,y,0]。接下来我们以5×5的点阵为例

from manim import*
class example(Scene):
    def construct(self):
       for x in range(-2,3):
           for y in range(2,-3,-1):
               dot = Dot([x,y,0],color = BLUE,radius = 0.4)
               self.play(Create(dot))

其中,color赋予dot一种颜色,radius赋予dot半径,可以根据需要自行改变

 三、线

1.直线

提供两个点,通过Line来进行划线

from manim import*

class example(Scene):

    def construct(self):

       line1 = Line([0,1,0],[1,3,0],color = RED_A,stroke_width = 5)

       self.play(Create(line1))

       line2 = Line([-1,-2,0],[-1,2,0],color = RED_E,stroke_width = 20)

       self.play(Create(line2))

在manim中每种color默认有五种色号从A到E,通过stroke_width可以调整线的粗细

 2.虚线

和直线类似,使用DashedLine调用

from manim import*
class example(Scene):
    def construct(self):
       line1 = DashedLine([-3,-2,0],[-3,2,0],color = RED_A,stroke_width = 5)
       self.play(Create(line1))
       line2 = DashedLine([-1,-2,0],[-1,2,0],color = RED_E,stroke_width = 20)
       self.play(Create(line2))
       self.wait(1)

3.箭头

使用Arrow调用箭头

from manim import*
class example(Scene):
    def construct(self):
       line1 = Arrow([0,-2,0],[0,2,0],color = RED_A,stroke_width = 5,tip_style ={"fill_opacity":0.5,"fill_color":BLUE_C,"stroke_color":YELLOW_D})
       self.play(Create(line1))
       self.wait(1)

在tip_style这个字典中你可以改变箭头的属性

4.圆弧

 1.使用Arc调用圆弧

from manim import*
class example(Scene):
    def construct(self):
       arc = Arc(arc_center = [1,-2,0],radius = 2,start_angle = PI/3,angle = PI/2)
       self.play(Create(arc))
       self.wait(1)

arc_center设置圆弧的圆心,radius设置圆弧的半径,start_angle设置圆弧的起始角度,angle设置圆弧结束点到圆心连线和起始点到圆心连线的夹角

2.两点式圆弧

from manim import*
class example(Scene):
    def construct(self):
       arc = ArcBetweenPoints(start = [0,-1,0],end = [0,1,0],angle = PI/2)
       self.play(Create(arc))
       self.wait(1)

start为起始点,end为结束点,angle为转过的角度

5.曲线箭头

使用CurvedArrow调用曲线箭头

from manim import*
class example(Scene):
    def construct(self):
       A = CurvedArrow(start_point = [1,1,0],end_point = [1,3,0])
       self.play(Create(A))
       self.wait(1)

start_point为箭头起始的位置,end_point为箭头结束的位置

 6.直角

利用Elbow,调用直角

from manim import*
class example(Scene):
    def construct(self):
       exp = Elbow(angle = 0,width = 3)
       self.play(Create(exp))
       self.wait(1)

通过angle调整直角面对的方向,

 7.切线

利用TangentLine调用切线

from manim import*
class example(Scene):
    def construct(self):
       exp = Circle(radius=2)
       line = TangentLine(vmob = exp,alpha = 0.6,length = 6)
       self.play(Create(exp))
       self.play(Create(line))
       self.wait(1)

vmob表示需要画切线的曲线,alpha为切点沿着曲线走过的长度和曲线总长的比值,length表示切线的长度。

四、面 

1.多边形

利用Polygon调用多边形

from manim import*
class example(Scene):
    def construct(self):
       exp = Polygon(np.array([1,2,0]),np.array([1,-3,0]),np.array([-1,-1,0]),np.array([-1,2,0]))
       self.play(Create(exp))
       self.wait(1)

输入n个点,自动生成多边形

2.正多边形

使用RegularPolygon,创造正n边形

from manim import*
class example(Scene):
    def construct(self):
       exp = RegularPolygon(n=6)
       self.play(Create(exp))
       self.wait(1)

 3.矩形

用Rectangle创造矩形

from manim import*
class example(Scene):
    def construct(self):
       exp = Rectangle(height = 2,width = 3)
       self.play(Create(exp))
       self.wait(1)

height设置矩形在y轴方向的长度,width设置矩形在x轴方向的长度

4.圆角矩形

通过RoundedRectangle创造圆角矩形

from manim import*
class example(Scene):
    def construct(self):
       exp = RoundedRectangle(corner_radius=PI/3)
       self.play(Create(exp))
       self.wait(1)

corner_radius表示圆角所对的角度 

5.圆

使用Circle创造圆

from manim import*
class example(Scene):
    def construct(self):
       exp = Circle(radius = 3)
       self.play(Create(exp))
       self.wait(1)

radius设置圆的半径

6.椭圆 

使用Ellipse创造一个椭圆

from manim import*
class example(Scene):
    def construct(self):
       exp = Ellipse(width = 4,height = 2)
       self.play(Create(exp))
       self.wait(1)

width为长轴的长度,height为短轴的长度

 7.环

使用Annulus创造圆环

from manim import*
class example(Scene):
    def construct(self):
       exp = Annulus(inner_radius = 1.5,outer_radius = 2.5)
       self.play(Create(exp))
       self.wait(1)

inter_radius为环的内径,outer_radius为环的外径

 8.扇

使用Sector创造扇

from manim import*
class example(Scene):
    def construct(self):
       exp = Sector(start_angle = PI/5,angle = PI/2)
       self.play(Create(exp))
       self.wait(1)

start_angle为开始时的角度,angle为扇形的角度

9.扇环 

使用AnnularSector创造扇环

from manim import*
class example(Scene):
    def construct(self):
       exp = AnnularSector(inner_radius = 1.5,outer_radius = 2.5,start_angle = PI/5,angle = PI/2)
       self.play(Create(exp))
       self.wait(1)

inter_radius为环的内径,outer_radius为环的外径,start_angle为开始时的角度,angle为扇形的角度

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值