-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
145 lines (122 loc) · 4.47 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from os import system
from manim import *
class CreateCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the color and transparency
self.play(Create(circle)) # show the circle on screen
class Shapes(Scene):
def construct(self):
circle = Circle()
square = Square()
triangle = Triangle()
circle.shift(LEFT)
square.shift(UP)
triangle.shift(RIGHT)
self.add(circle, square, triangle)
self.wait(1)
class RunTime(Scene):
def construct(self):
square = Square()
self.add(square)
self.play(square.animate.shift(UP), run_time=3)
self.wait(1)
class Count(Animation):
def __init__(self, number: DecimalNumber, start: float, end: float, **kwargs) -> None:
# Pass number as the mobject of the animation
super().__init__(number, **kwargs)
# Set start and end
self.start = start
self.end = end
def interpolate_mobject(self, alpha: float) -> None:
# Set value of DecimalNumber according to alpha
value = self.start + (alpha * (self.end - self.start))
self.mobject.set_value(value)
class CountingScene(Scene):
def construct(self):
# Create Decimal Number and add it to scene
number = DecimalNumber().set_color(WHITE).scale(5)
# Add an updater to keep the DecimalNumber centered as its value changes
number.add_updater(lambda number: number.move_to(ORIGIN))
self.add(number)
self.wait()
# Play the Count Animation to count from 0 to 100 in 4 seconds
self.play(Count(number, 0, 100), run_time=4, rate_func=linear)
self.wait()
class HelloWorld(Scene):
def construct(self):
circle=Circle()
blue_circle=circle.set_color(BLUE).set_opacity(0.8)
label=Text("A circle appears")
self.play(Write(label))
self.play(label.animate.next_to(blue_circle,UP,buff=0.5))
self.wait(1)
self.play(Create(blue_circle))
self.wait(1)
class AnitmateDemo(Scene):
def construct(self):
triangle=Triangle(color=RED,fill_opacity=0.8)
self.play(DrawBorderThenFill(triangle))
self.play(triangle.animate.shift(LEFT))
self.play(triangle.animate.shift(RIGHT).scale(3))
self.play(triangle.animate.rotate(PI/3))
self.play(triangle.animate.set_color(BLUE))
class FormulaEmphasis(Scene):
def construct(self):
product_formula = MathTex(
r"\frac{d}{dx} f(x)g(x) =",
r"f(x) \frac{d}{dx} g(x)",
r"+",
r"g(x) \frac{d}{dx} f(x)"
)
self.play(Write(product_formula))
box1 = SurroundingRectangle(product_formula[1], buff=0.1)
box2 = SurroundingRectangle(product_formula[3], buff=0.1)
self.play(Create(box1))
self.wait()
self.play(Transform(box1, box2))
self.wait()
class OpeningManim(Scene):
def construct(self):
title = Tex(r"This is some \LaTeX")
basel = MathTex(r"\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}")
VGroup(title, basel).arrange(DOWN)
self.play(
Write(title),
FadeIn(basel, shift=UP),
)
self.wait()
transform_title = Tex("That was a transform")
transform_title.to_corner(UP + LEFT)
self.play(
Transform(title, transform_title),
LaggedStart(*[FadeOut(obj, shift=DOWN) for obj in basel]),
)
self.wait()
grid = NumberPlane(x_range=(-10, 10, 1), y_range=(-6.0, 6.0, 1))
grid_title = Tex("This is a grid")
grid_title.scale(1.5)
grid_title.move_to(transform_title)
self.add(grid, grid_title)
self.play(
FadeOut(title),
FadeIn(grid_title, shift=DOWN),
Create(grid, run_time=3, lag_ratio=0.1),
)
self.wait()
grid_transform_title = Tex(
r"That was a non-linear function \\ applied to the grid"
)
grid_transform_title.move_to(grid_title, UL)
grid.prepare_for_nonlinear_transform()
self.play(
grid.animate.apply_function(
lambda p: p + np.array([np.sin(p[1]), np.sin(p[0]), 0])
),
run_time=3,
)
self.wait()
self.play(Transform(grid_title, grid_transform_title))
self.wait()
if __name__ == "__main__":
system("manim -pql main.py OpeningManim")