99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹
Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹
2022-03-09
收藏

來源:Python數(shù)據(jù)之道

作者:陽哥

01、寫在前面

最近幾個(gè)月,我在微信視頻號(hào)「價(jià)值前瞻」和「Python數(shù)據(jù)之道」發(fā)布了一些視頻,有不少同學(xué)問到這些視頻是怎么做的,用什么工具制作的。

在文章 用 python 制作高逼格的數(shù)學(xué)動(dòng)畫 中,我跟大家介紹了 Manim 這個(gè)視頻制作工具,以及以及案例演示。

不少同學(xué)覺得這個(gè)工具不錯(cuò),問到有沒有完整的使用教程或者相關(guān)書籍。據(jù)我所知,目前應(yīng)該是沒有專門的書籍來介紹這個(gè)工具的。至于教程,不同版本的Manim有一部分文檔,其中 Manim社區(qū)版的文檔相對(duì)而言要完善些。

本次,我將基于 Manim社區(qū)版(Manim Community)給大家分享Manim入門的第一部分,基礎(chǔ)形狀的使用。

本次使用的版本為 Manim Community v0.14.0,文中介紹的基礎(chǔ)形狀如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

02、Manim的安裝與運(yùn)行

安裝

如何安裝社區(qū)版Manim,參見下面的官方鏈接:

https://docs.manim.community/en/stable/installation.html

如何運(yùn)行 Manim

用 Manim 繪制圖形,首先需要引入 Manim 庫,然后將需要繪制的內(nèi)容封裝到一個(gè) 類(class) 里面。

社區(qū)版的導(dǎo)入代碼如下:

from manim import *

對(duì)于 編輯好的程序文件( XXXX.py 文件),需要在同一個(gè)文件夾下運(yùn)行命令來運(yùn)行程序,命令格式如下:

manim -pql XXXX.py DemoSquare 

上面的命令行中:

  • manim 是社區(qū)版Manim運(yùn)行程序的主要標(biāo)志用語;
  • p 表示程序運(yùn)行后會(huì)進(jìn)行預(yù)覽(圖片或視頻);
  • ql 表示低質(zhì)量(quality low), 其他的選項(xiàng)有 -ql-qm-qh-qk, 分別表示 低質(zhì)量、正常質(zhì)量、高質(zhì)量、4K質(zhì)量;
  • XXXX.py 是py代碼文件;
  • DemoSquare 是 py代碼文件中的一個(gè)類;

演示過程錄屏如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

命令行中,還有其他許多參數(shù)可以設(shè)置,可以通過社區(qū)版的支持文檔來進(jìn)一步了解:

https://docs.manim.community/en/stable/tutorials/configuration.html#command-line-arguments

03、Manim 的基礎(chǔ)形狀介紹

通用屬性

Manim 中基礎(chǔ)形狀有些屬性和方法,對(duì)于大部分形狀是通用的,因此在介紹具體的形狀之前,在這里通過 正方形 來講解下形狀的基礎(chǔ)用法。

在下面的案例中,實(shí)現(xiàn)了對(duì)正方形的邊框顏色設(shè)置、線寬度設(shè)置、填充顏色、旋轉(zhuǎn)、大小變換等。

# manim -pql manimce-intro-01.py DemoSquare class DemoSquare(Scene): def construct(self):
        WaterMark.construct(self)
        r = 1 sq1 = Square(
            side_length=2 * r,
            color=BLUE,
        )
        sq1.to_corner(UL,buff=2) self.add(sq1) self.wait()

        sq2 = Square(
            side_length=2 * r,
            color=BLUE,
            stroke_width=10, # 設(shè)置邊框線的粗細(xì) )
        sq2.next_to(sq1,RIGHT,buff=1) self.add(sq2) self.wait()

        sq3 = Square(
            side_length=2 * r,
            color=BLUE,
            fill_color=ORANGE, # 設(shè)置填充顏色 fill_opacity=0.5, # 設(shè)置透明度 )
        sq3.next_to(sq2,RIGHT,buff=1) self.add(sq3) self.wait() # 形狀大小變換 sq4 = sq1.copy()
        sq4.scale(0.6) # 縮小到 60% sq4.next_to(sq1,DOWN,buff=0.5) self.add(sq4) self.wait() # 形狀旋轉(zhuǎn) sq5 = sq2.copy()
        sq5.rotate(45*DEGREES) # 旋轉(zhuǎn)45度 sq5.next_to(sq2,DOWN,buff=0.5) self.add(sq5) self.wait()

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

點(diǎn)

對(duì)于 點(diǎn) , manim 中目前有幾種不一樣的形狀可以來展示,包括:

  • Dot
  • AnnotationDot
  • LabeledDot
class DemoDot(Scene): def construct(self):
        WaterMark.construct(self)
        g = Group( # 點(diǎn) Dot(color=PINK),
            AnnotationDot(stroke_color=YELLOW, fill_color=BLUE,fill_opacity=1), # 帶文字標(biāo)簽的點(diǎn) LabeledDot(Tex("2022", color=RED)),
            LabeledDot(MathTex("a", color=GREEN)),
            LabeledDot(Text("Python數(shù)據(jù)之道", color=BLUE)).scale(0.3),
            LabeledDot("Lemon"),
        )
        g.arrange(RIGHT,buff=0.5).scale(1.5)
        g[:2].move_to(UP*1.5)
        g[2:].next_to(g[:2],DOWN,buff=1) for shape in g: self.add(shape) self.wait(0.5)

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

在這里, 的形狀,包括 直線、虛線、箭頭、雙箭頭、彎曲的箭頭等,如下:

  • Line
  • DashedLine
  • Arrow
  • DoubleArrow
  • CurvedArrow
class DemoLine(Scene): def construct(self):
        WaterMark.construct(self)
        g = Group( # 線 Line(0.5*LEFT,0.5*RIGHT,color=YELLOW), # 虛線 DashedLine(0.5*LEFT,0.5*RIGHT,color=TEAL), # 箭頭 Arrow(color=BLUE), 
            Arrow(color= BLUE, tip_shape=ArrowCircleFilledTip), #  ArrowCircleTip Arrow(color= BLUE, tip_shape=ArrowSquareTip),# ArrowSquareFilledTip # 雙箭頭 DoubleArrow(color=BLUE), # 彎曲的箭頭 CurvedArrow(LEFT,RIGHT,angle=90*DEGREES,color= BLUE), 
        )
        g.arrange(RIGHT,buff=0.5)
        g[:3].move_to(UP*1.5)
        g[3:].next_to(g[:3],DOWN,buff=1) for shape in g: self.add(shape) self.wait(0.5)

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

圓形

圓形包括 圓、圓環(huán)、扇形、橢圓、弧形等,如下:

  • Circle
  • Annulus
  • Ellipse
  • Sector
  • Arc
  • ArcBetweenPoints
class DemoCircle(Scene): def construct(self):
        WaterMark.construct(self)
        g = Group( # 圓形 Circle(radius=0.8,color=YELLOW,fill_color=BLUE,fill_opacity=1), # 圓環(huán) Annulus(inner_radius=0.7, outer_radius=1,fill_color= DARK_BLUE, stroke_color=YELLOW, stroke_width=4), # 橢圓 Ellipse(color= BLUE), # 扇形 Sector(inner_radius=0.7, outer_radius=1,fill_color= BLUE, stroke_color=YELLOW, stroke_width=4), # 弧形 Arc(radius=1.3, start_angle=-PI/8, angle=PI,color= BLUE),
            ArcBetweenPoints(start=2 * RIGHT, end=2*LEFT, stroke_color=BLUE) ,
        )
        g.arrange(RIGHT,buff=0.5)
        g[:3].move_to(UP*1.5)
        g[3:].next_to(g[:3],DOWN,buff=1) for shape in g: self.add(shape) self.wait(0.5)

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

矩形

矩形類的形狀,是咱們經(jīng)常使用到的一類圖形,在 manim 中包括:

  • Rectangle
  • RoundedRectangle
  • Square
class DemoRect(Scene): def construct(self):
        WaterMark.construct(self)
        g = Group( # 矩形 Rectangle(width=1,height=0.6,color=BLUE,fill_color=ORANGE,fill_opacity=1),
            Rectangle(width=1,height=0.6,color=BLUE,grid_xstep=0.5,grid_ystep=0.2), # 圓角矩形 RoundedRectangle(corner_radius=0.3,width=1,height=0.6,fill_color=PURPLE,fill_opacity=1), # 正方形 Square(
            side_length=1,
            color=BLUE,
            fill_color=ORANGE, # 設(shè)置填充顏色 fill_opacity=0.5, # 設(shè)置透明度 ),
        )
        g.arrange(RIGHT,buff=0.5).scale(2) for shape in g: self.add(shape) self.wait(0.5)

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

多邊形

多邊形性,相對(duì)來說要復(fù)雜些,主要是需要設(shè)置邊緣點(diǎn)的位置,在manim中有多種方式來表示多邊形,包括:

  • Triangle
  • Polygon
  • RegularPolygon
  • Star
  • Polygram
  • RegularPolygram
class DemoPolygon(Scene): def construct(self): WaterMark.construct(self) g = Group( # 正三角形 Triangle(radius=2,color=BLUE), # 三角形 Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0]), # 多邊形 Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-2.5, -2, 0], [-4.5, -1.5, 0]), #正多邊形 RegularPolygon(n=6,color=BLUE), # 星型 Star(color=BLUE), #多邊形 Polygram( [[0, 2, 0], [-np.sqrt(3), -1, 0], [np.sqrt(3), -1, 0]], [[-np.sqrt(3), 1, 0], [0, -2, 0], [np.sqrt(3), 1, 0]],), RegularPolygram(num_vertices = 7), RegularPolygram(5, radius=1), ) g.arrange(RIGHT,buff=0.5).scale(0.7) g[:4].move_to(UP*1.5) g[4:].next_to(g[:3],DOWN,buff=1) for shape in g: self.add(shape) self.wait(0.5) 

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

符號(hào)

在manim 中,也經(jīng)常會(huì)用到 大括號(hào)等形狀,如下:

class DemoCross(Scene): def construct(self):
        WaterMark.construct(self) # 十字叉 cross = Cross(stroke_color = BLUE,stroke_width=20).scale(0.8)
        cross.to_corner(UL,buff=2) self.add(cross) self.wait(0.5) # 大括號(hào) br1 = Brace(Line(LEFT,RIGHT),color= BLUE)
        br1.next_to(cross,RIGHT,buff=0.5) self.add(br1) self.wait(0.5) # 帶文字的大括號(hào) line=Line(LEFT,RIGHT) 
        br2= BraceLabel(line, text= "14cm", color= YELLOW, buff=0.1) 
        br2.submobjects[1].set_color(BLUE) self.add(VGroup(line,br2).next_to(br1,RIGHT,buff=0.5)) self.wait(0.5) # 帶弧度的大括號(hào) arc = Arc(radius=1,start_angle=0,angle=3*PI/4) 
        br3 = ArcBrace(arc).set_color(BLUE) self.add(VGroup(arc,br3).next_to(VGroup(line,br2),RIGHT,buff=0.5)) # self.add(arc,br3) self.wait(0.5)

演示效果如下:

Python視頻制作工具M(jìn)anim入門,基礎(chǔ)形狀詳細(xì)介紹

04、小結(jié)

相對(duì)而言,manim 中的基礎(chǔ)形狀,還是比較齊全的,在這些基礎(chǔ)形狀的基礎(chǔ)上,自己可以進(jìn)一步來組合其他的形狀。

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請(qǐng)參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }