當前檔案版本:v0.16.0.post0
本文所有物體都繼承自此,故很多引數只在本部分闡述。
VMobject繼承自Mobject
V的意思是向量化的,vectorized mobject
構造引數:
本節列舉大量常用的幾何圖形。
manim.mobject.geometry
manim.mobject.geometry.arc.Circle
構造引數:
構造範例:
from manim import *
class CircleExample(Scene):
def construct(self):
circle_1 = Circle(radius=1.0)
circle_2 = Circle(radius=1.5, color=GREEN)
circle_3 = Circle(radius=1.0, color=BLUE_B, fill_opacity=1)
circle_group = Group(circle_1, circle_2, circle_3).arrange(buff=1)
self.add(circle_group)
manim.mobject.geometry.arc.Dot
構造引數:
構造範例:
from manim import *
class DotExample(Scene):
def construct(self):
dot1 = Dot(point=LEFT, radius=0.08)
dot2 = Dot(point=ORIGIN)
dot3 = Dot(point=RIGHT)
self.add(dot1,dot2,dot3)
manim.mobject.geometry.arc.Ellipse
構造引數:
構造範例:
from manim import *
class EllipseExample(Scene):
def construct(self):
ellipse_1 = Ellipse(width=2.0, height=4.0, color=BLUE_B)
ellipse_2 = Ellipse(width=4.0, height=1.0, color=BLUE_D)
ellipse_group = Group(ellipse_1,ellipse_2).arrange(buff=1)
self.add(ellipse_group)
manim.mobject.geometry.line.Angle
構造引數:
構造範例:
from manim import *
class RightArcAngleExample(Scene):
def construct(self):
line1 = Line( LEFT, RIGHT )
line2 = Line( DOWN, UP )
rightarcangles = [
Angle(line1, line2, dot=True),
Angle(line1, line2, radius=0.4, quadrant=(1,-1), dot=True, other_angle=False),
Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, dot=True, dot_color=YELLOW, dot_radius=0.04, other_angle=True),
Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, dot=True, dot_color=GREEN, dot_radius=0.08),
]
plots = VGroup()
for angle in rightarcangles:
plot=VGroup(line1.copy(),line2.copy(), angle)
plots.add(plot)
plots.arrange(buff=1.5)
self.add(plots)
manim.mobject.geometry.line.Line
構造引數:
構造範例:
from manim import *
class LineExample(Scene):
def construct(self):
ax = Axes()
line1 = Line(ax.c2p(1,-3),ax.c2p(1,3),buff=0)
line2 = Line(ax.c2p(2,-3),ax.c2p(2,3),buff=1)
line3 = Line(ax.c2p(2,-3),ax.c2p(2,3),path_arc=PI)
self.add(ax,line1,line2,line3)
manim.mobject.geometry.polygram.Rectangle
構造引數:
構造範例:
from manim import *
class RectangleExample(Scene):
def construct(self):
rect1 = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
rect2 = Rectangle(width=1.0, height=4.0)
rects = Group(rect1,rect2).arrange(buff=1)
self.add(rects)
manim.mobject.geometry.polygram.Square
構造引數:
構造範例:
from manim import *
class SquareExample(Scene):
def construct(self):
square = Square(side_length=2.0,
color=BLUE,fill_opacity=1,sheen_factor=0.8)
self.add(square)
manim.mobject.geometry.polygram.Star
構造引數:
構造範例:
from manim import *
class StarExample(Scene):
def construct(self):
pentagram = RegularPolygram(5, radius=2).to_edge(LEFT)
star = Star(outer_radius=2, color=RED).next_to(pentagram,RIGHT)
sum = VGroup(
pentagram.copy().to_edge(RIGHT),
star.copy().to_edge(RIGHT))
self.add(pentagram,star,sum)
from manim import *
class StarExample(Scene):
def construct(self):
pentagram = RegularPolygram(7, radius=2).to_edge(LEFT)
star = Star(n=7,outer_radius=2, color=RED).next_to(pentagram,RIGHT)
sum = VGroup(
pentagram.copy().to_edge(RIGHT),
star.copy().to_edge(RIGHT))
self.add(pentagram,star,sum)
manim.mobject.geometry.polygram.Triangle
構造引數:
構造範例:
from manim import *
class TriangleExample(Scene):
def construct(self):
triangle_1 = Triangle()
triangle_2 = Triangle().scale(2).rotate(60*DEGREES)
tri_group = Group(triangle_1, triangle_2).arrange(buff=1)
self.add(tri_group)
manim.mobject.geometry.shape\_matchers.SurroundingRectangle
構造引數:
構造範例:
from manim import *
class SurroundingRectExample(Scene):
def construct(self):
title = Title("Fourier Transform")
quote = Text('''
Generally speaking, the two ways to describe the same problem
can be called that they are the mutual transform to each other.
''',color=BLUE,
).scale(0.75)
box = SurroundingRectangle(quote, color=YELLOW, buff=MED_LARGE_BUFF)
t2 = Tex(r"Hello World").scale(1.5)
box2 = SurroundingRectangle(t2, corner_radius=0.2)
mobjects = VGroup(VGroup(box, quote), VGroup(t2, box2)).arrange(DOWN)
self.add(title, mobjects)
manim.mobject.geometry.shape\_matchers.Underline
構造引數:
構造範例:
from manim import *
class UnderLine(Scene):
def construct(self):
man = MathTex("Manim \enspace Remoo") # Full Word
ul = Underline(man) # Underlining the word
self.add(man, ul)
本節主要儘可能詳細的列舉需要使用的數學影象VMobject。
manim.mobject.graphing
manim.mobject.graphing.coordinate\_systems.Axes
構造引數:
構造範例:
from manim import *
class AxesExample(Scene):
def construct(self):
ax1 = Axes(
x_range=[-2*2*PI,2*2*PI,PI],
y_range=[-1,1,0.5],
x_length=6,
tips=True).to_edge(LEFT)
graph1 = ax1.plot(lambda x : np.sin(x))
ax2 = Axes(
x_range=[-1,4,1],
y_range=[-2,2,1],
x_length=6,
tips=False).to_edge(RIGHT)
graph2 = VGroup(*(Dot(ax2.c2p(x-1,2-x)) for x in range(5)))
self.add(ax1,graph1,ax2,graph2)
from manim import *
class LogScalingExample(Scene):
def construct(self):
ax = Axes(
x_range=[0, 10, 1],
y_range=[-2, 6, 1],
tips=False,
axis_config={"include_numbers": True},
y_axis_config={"scaling": LogBase(custom_labels=True)},
)
graph = ax.plot(lambda x: x ** 2, x_range=[0.001, 10,0.01])
self.add(ax, graph)