栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > Python

Manim文档及源码笔记-CE教程BE01英文笔记速览版

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Manim文档及源码笔记-CE教程BE01英文笔记速览版

Manim文档及源码笔记-CE教程BE01 An Invitaion to Mathematical Animations WITH EASE in Python

这次筛选到了Behackl博士的教程,逐步拆解,更为细腻~
参考视频在此【或请自行搜索上面的英文标题】;
本页中文版传送门【建设中】;

首先,国际通则:Just GET STARTED~ JUST DO IT~

然后,让我们行动起来~

Part 1 Things to know before you start History is complicated: different versions!

CAUTION:
There are several incompatible versions of Manim floatong around.

  • Manim: the community maintained version
  • 3b1b/manim- manimgl- manimlib: the original version,
    devdloped+ maintained mainly by Grant “3b1b” Sanderson
How do I install Manim?
  • Two ingredients: FFmpeg and Python( 3.7+ )
  • Optional( but useful) : a LaTeX distribution like MiKTeX/TeXLive
  • Caution: most installation videos are outdated!
    Go to docs.manim.community and follow installation instructions for your OS!
Help and other resources?
  • All community resources: www.manim.community
  • Places to get help:
    • Manim Discord server: manim.community/discord
    • Reddit: reddit.com/r/manim
    • GitHub discussions: github.com/ManimCommunity/manim
  • Make sure to code + output when asking a question!
  • Interactive worksheet: see description!
Part 2 Basic anatomy of Manimations Learning by Doing!

注:
1、代码实践过程根据运行环境及笔记需要略有改动;
2、经过实践理解,加入了一些自己的注释;
3、常见问题及大概率解决方案:

  • Python相关:注意缩进、冒号,中英文字符、大小写;
  • Manim相关:安装与运行环境;
  • Coding相关:检查拼写;
代码直击前-开头别忘了:
from manim import *
config.media_width="60%"
代码直击1 FirstExample
%%manim -v WARNING -qm FirstExample

class FirstExample(Scene):
    def construct(self):
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)
        green_square=Square(color=GREEN,fill_opacity=0.8)
        green_square.next_to(blue_circle,RIGHT)
        self.add(blue_circle,green_square)

注:ManimCE自动生成图片文件夹;

用VSCode右键这里,很方便打开相应文件夹;

Generating Output …the “normal” way:
  • Write code in file.py
  • Then run manim -qm -p file.py FirstExample in terminal
…with Jupyter
  • Import manim, put code for scene in a cell
  • %%manim -qm FirstExample at beginning of cell, then run it
Scene, Mobjects, globla constants
  • Scene: animation canvas
  • Mobjects: Manim objects- Circle, Square, …
  • Mobjects have properties- color, fill_opacity, …
  • Some global constants: colors( BLUE, GREEN, …) and directions(UP, DOWN, RIGHT, …)

The reference manual at docs.manim.community lists all available classes and functions!

代码直击2 SecondExample
%%manim -v WARNING -qm SecondExample
class SecondExample(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        self.add(ax, curve)

代码直击3 SecondExample2
%%manim -v WARNING -qm SecondExample2
class SecondExample2(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
        self.add(ax, curve)

Part 3 Where are the animations?! add, wait, play- Animations!
  • Scene.add adds Mobjects immediately to the scene
  • Scene.wait adds a pause
  • Scene.play plays animations
  • Animations can …
    • add mobjects( Create, FadeIn, …)
    • change mobjects( Transform, …)
    • emphasize mobjects( Indicate, Circumscribe,…)
    • remove mobjects( Uncreate, FadeOut, …)
代码直击4
%%manim -v WARNING -qm SecondExample2
class SecondExample2(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
        self.add(ax)
        self.play(Create(ax))

SecondExample2

注:ManimCE自动生成视频文件夹;

代码直击5
%%manim -v WARNING -qm SecondExample3
class SecondExample3(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
    #    self.add(ax)
        self.play(Create(ax))
        self.play(Create(curve))
        self.wait(2)

SecondExample3

代码直击6
%%manim -v WARNING -qm SecondExample4
class SecondExample4(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
    #    self.add(ax)
        self.play(Create(ax),Create(curve))
   
        self.wait(2)

SecondExample4

代码直击7
%%manim -v WARNING -qm SecondExample5
class SecondExample5(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
    #    self.add(ax)
        self.play(Create(ax),Create(curve))
        self.play(FadeIn(area))
        self.wait(2)

SecondExample5

    #   self.play(Create(ax),Create(curve))
        self.play(Create(ax),Create(curve),run_time=3)
    #   self.play(Create(ax),Create(curve))
    #   self.play(Create(ax),Create(curve),run_time=3)
        self.play(Create(ax,run_time=2),Create(curve),run_time=5)
代码直击8
%%manim -v WARNING -qm SquareToCircle

class SquareToCircle(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))

SquareToCircle

代码直击9
%%manim -v WARNING -qm SquareToCircle1

class SquareToCircle1(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)

        self.play(Transform(green_square,blue_circle))
        self.wait(2)

SquareToCircle1

代码直击10
%%manim -v WARNING -qm SquareToCircle2a

class SquareToCircle2a(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)

        self.play(Transform(green_square,blue_circle))
        self.play(FadeOut(blue_circle))
        #self.wait(2)
代码直击11
%%manim -v WARNING -qm SquareToCircle2b

class SquareToCircle2b(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)

        self.play(Transform(green_square,blue_circle))
        #self.play(FadeOut(blue_circle))
        self.play(FadeOut(green_square))
        #self.wait(2)
代码直击12
%%manim -v WARNING -qm SquareToCircle2c

class SquareToCircle2c(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)

        #self.play(Transform(green_square,blue_circle))
        self.play(ReplacementTransform(green_square,blue_circle))
        
        self.play(FadeOut(blue_circle))
        #self.play(FadeOut(green_square))
        #self.wait(2)

SquareToCircle2c

代码直击13
%%manim -v WARNING -qm SquareToCircle3

class SquareToCircle3(Scene):
    def construct(self):
        green_square=Square(color=GREEN,fill_opacity=0.5)
        #self.add(green_square)
        self.play(DrawBorderThenFill(green_square))
        blue_circle=Circle(color=BLUE,fill_opacity=0.5)
        
        self.play(ReplacementTransform(green_square,blue_circle))
        #self.play(FadeOut(blue_circle))
        self.play(Indicate(blue_circle))
        
        #self.wait(2)

SquareToCircle3

Extra Try
%%manim -v WARNING -qm ExtraTry1
class ExtraTry1(Scene):
    def construct(self):
        ax=Axes(x_range=(-3,3),y_range=(-3,3))
        curve=ax.plot(lambda x: (x+2)*x*(x-2)/2,color=RED)
        area=ax.get_area(curve, x_range=(-2,0))
    #    self.add(ax)
        self.play(Create(ax),Create(curve))
        self.play(FadeIn(area))
        self.play(Indicate(ax))
        self.play(Indicate(curve))
        self.play(Indicate(area))

        #self.wait(2)

ExtraTry1

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/1038400.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号