-
Notifications
You must be signed in to change notification settings - Fork 3
/
mobjects.py
92 lines (76 loc) · 2.94 KB
/
mobjects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from big_ol_pile_of_manim_imports import *
class Mobjects(Scene):
'''
Examples of the mobjects available in the manim library.
(manimlib/mobject)
'''
def construct(self):
# TextMobject
text_mobject = TextMobject("TextMobject")
self.play(Write(text_mobject))
self.wait()
self.play(FadeOut(text_mobject))
# TexMobject
tex_mobject = TextMobject("TexMobject")
tex_mobject.shift(UP)
formula = TexMobject("\sum_{k=0}^\\infty \\frac{c}{k^2} = \\frac{8\\pi^2}{996}")
formula.shift(UP)
formula.next_to(tex_mobject, DOWN)
self.play(Write(tex_mobject), Write(formula))
self.wait()
self.play(FadeOut(tex_mobject), FadeOut(formula))
# number line
number_line = NumberLine()
number_line.add_numbers()
self.play(ShowCreation(number_line, submobject_mode = "one_at_a_time"))
number_line_text = TextMobject("NumberLine")
number_line_text.shift(UP)
self.play(Write(number_line_text))
self.wait()
self.play(FadeOut(number_line_text))
self.play(FadeOut(number_line))
# plane
plane = NumberPlane()
self.play(
ShowCreation(plane, summobject_mode = "lagged_start")
)
plane_text = TextMobject("NumberPlane")
plane_text.to_edge(UP)
self.play(Write(plane_text))
# vector
vector = Vector([-2, 3])
self.show_mobject("Vector", vector, GrowArrow,
shift=UP+2*LEFT)
# dot
self.show_mobject("Dot", Dot(radius = 0.1).set_color(RED),
GrowFromCenter, shift=0.5*(UP+LEFT))
self.show_mobject("Line", Line(ORIGIN, UP+2*RIGHT), ShowCreation,
shift=1.5*(UP+0.5*RIGHT))
graph = ParametricFunction(
lambda t : 4*t*RIGHT + 2*smooth(t)*UP
)
graph_line = Line(graph.points[0], graph.points[-1], color = WHITE)
graph_text = TextMobject("ParametricFunction")
graph_text.next_to(graph, 0.5*UP+2*LEFT)
self.play(ShowCreation(graph), Write(graph_text))
self.play(Transform(graph, graph_line))
self.play(Uncreate(graph), FadeOut(graph_text))
self.play(FadeOut(plane_text))
self.play(FadeOut(plane))
def show_mobject(self, name, obj, animate, shift=None, text=None):
if text is None:
text = TextMobject(name)
if shift is not None:
text.shift(shift)
self.play(animate(obj), Write(text))
self.wait()
if name == "Line":
brace = Brace(obj)
label = TextMobject("Brace").next_to(brace, DOWN).scale(0.7)
self.play(GrowFromCenter(brace))
self.play(Write(label))
self.wait()
self.play(Uncreate(label), FadeOut(brace), Uncreate(text), FadeOut(obj))
return
self.play(Uncreate(text), FadeOut(obj))
self.wait()