1 import time
2
3 import numpy as np
4 from manim import *
5
6 class BooleanOperations(Scene):
7 def construct(self):
8 circle=Circle()
9 square=Square()
10 square.rotate(np.pi/8)
11 self.play(ShowCreationThenFadeOut(square))
12 self.play(Transform(square,circle))
13 self.wait(1)
这是我们遇到的第一个例子,按照行号的顺序详细说明一下:
6行:建立一个场景,名字叫做 BooleanOperations
7行:创建场景的方法
8行:创建一个圆,命名为circle
9行:创建一个正方形,命名为square
10行:将square旋转π/8
11行:播放square的创造过程
12行:播放square到circle的变换过程
13行:停顿1秒,随后结束 (self.dither可能无法使用)
from manim import *
class CreateCircle(Scene):
def construct(self):
circle=Circle()
circle.set_fill(PINK,opacity=1)
self.play(ShowCreationThenFadeOut(circle))
self.wait()
circle=Circle()
circle.set_fill(PINK,opacity=0.5) 表示两行创建一个圆并设置其颜色和不透明度。
class SquareToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set color and transparency
square = Square() # create a square
square.rotate(PI / 4) # rotate a certain amount
self.play(Create(square)) # animate the creation of the square
self.play(Transform(square, circle)) # interpolate the square into the circle
self.play(FadeOut(square)) # fade out animation
square=Square() 创建一个正方形 square.rotate(PI/4) 旋转π/4 self.play(ShowCreationThenFadeOut(square)) 在视频中展现 self.play(Transform(square,circle)) 从正方形转化为圆形 self.play(FadeOut(square)) : FadeIn(淡入)FadeOut(淡出)