1
1
from manim import *
2
2
3
+
3
4
class FoundationalMath (Scene ):
4
5
def construct (self ):
5
6
text = Tex ("Foundational Math Concepts" ).scale (1.5 )
@@ -13,7 +14,7 @@ def construct(self):
13
14
# Create sets A and B
14
15
circle_a = Circle (radius = 2 , color = BLUE , fill_opacity = 0.5 ).shift (LEFT )
15
16
circle_b = Circle (radius = 2 , color = GREEN , fill_opacity = 0.5 ).shift (RIGHT )
16
-
17
+
17
18
text_a = Tex ("A" ).move_to (circle_a .get_center ())
18
19
text_b = Tex ("B" ).move_to (circle_b .get_center ())
19
20
@@ -23,28 +24,62 @@ def construct(self):
23
24
# Union of A and B
24
25
union_text = Tex ("A $\cup$ B" ).to_corner (UP )
25
26
self .play (Write (union_text ))
26
- union_region = Intersection (circle_a , circle_b ).set_color (YELLOW ).set_fill (YELLOW , opacity = 0.5 )
27
- union_region_a = Difference (circle_a , circle_b ).set_color (YELLOW ).set_fill (YELLOW , opacity = 0.5 )
28
- union_region_b = Difference (circle_b , circle_a ).set_color (YELLOW ).set_fill (YELLOW , opacity = 0.5 )
27
+ union_region = (
28
+ Intersection (circle_a , circle_b )
29
+ .set_color (YELLOW )
30
+ .set_fill (YELLOW , opacity = 0.5 )
31
+ )
32
+ union_region_a = (
33
+ Difference (circle_a , circle_b )
34
+ .set_color (YELLOW )
35
+ .set_fill (YELLOW , opacity = 0.5 )
36
+ )
37
+ union_region_b = (
38
+ Difference (circle_b , circle_a )
39
+ .set_color (YELLOW )
40
+ .set_fill (YELLOW , opacity = 0.5 )
41
+ )
29
42
self .play (FadeIn (union_region_a ), FadeIn (union_region_b ), FadeIn (union_region ))
30
43
self .wait ()
31
- self .play (FadeOut (union_region_a ), FadeOut (union_region_b ), FadeOut (union_region ), FadeOut (union_text ))
32
-
44
+ self .play (
45
+ FadeOut (union_region_a ),
46
+ FadeOut (union_region_b ),
47
+ FadeOut (union_region ),
48
+ FadeOut (union_text ),
49
+ )
50
+
33
51
# Intersection of A and B
34
52
intersection_text = Tex ("A $\cap$ B" ).to_corner (UP )
35
53
self .play (Write (intersection_text ))
36
- intersection_region = Intersection (circle_a , circle_b ).set_color (YELLOW ).set_fill (YELLOW , opacity = 0.5 )
54
+ intersection_region = (
55
+ Intersection (circle_a , circle_b )
56
+ .set_color (YELLOW )
57
+ .set_fill (YELLOW , opacity = 0.5 )
58
+ )
37
59
self .play (FadeIn (intersection_region ))
38
60
self .wait ()
39
61
self .play (FadeOut (intersection_region ), FadeOut (intersection_text ))
40
62
41
63
# Complement of A
42
64
complement_text = Tex ("A$^c$" ).to_corner (UP )
43
65
self .play (Write (complement_text ))
44
- complement_region = Difference (Rectangle (width = 10 , height = 10 , color = WHITE ).move_to (ORIGIN ), circle_a ).set_color (YELLOW ).set_fill (YELLOW , opacity = 0.5 )
66
+ complement_region = (
67
+ Difference (
68
+ Rectangle (width = 10 , height = 10 , color = WHITE ).move_to (ORIGIN ), circle_a
69
+ )
70
+ .set_color (YELLOW )
71
+ .set_fill (YELLOW , opacity = 0.5 )
72
+ )
45
73
self .play (FadeIn (complement_region ))
46
74
self .wait ()
47
- self .play (FadeOut (complement_region ), FadeOut (complement_text ), FadeOut (circle_a ), FadeOut (circle_b ), FadeOut (text_a ), FadeOut (text_b ))
75
+ self .play (
76
+ FadeOut (complement_region ),
77
+ FadeOut (complement_text ),
78
+ FadeOut (circle_a ),
79
+ FadeOut (circle_b ),
80
+ FadeOut (text_a ),
81
+ FadeOut (text_b ),
82
+ )
48
83
49
84
50
85
class FunctionGraphs (Scene ):
@@ -73,29 +108,43 @@ def quadratic_function(x):
73
108
return 0.2 * x ** 2 - 1
74
109
75
110
quadratic_graph = axes .plot (quadratic_function , color = GREEN )
76
- quadratic_label = axes .get_graph_label (quadratic_graph , "y = 0.2x^2 - 1" , direction = UR )
111
+ quadratic_label = axes .get_graph_label (
112
+ quadratic_graph , "y = 0.2x^2 - 1" , direction = UR
113
+ )
77
114
self .play (Create (quadratic_graph ), Write (quadratic_label ))
78
115
self .wait ()
79
116
80
117
# Exponential function
81
118
def exponential_function (x ):
82
- return 2 ** x / 5
119
+ return 2 ** x / 5
83
120
84
121
exponential_graph = axes .plot (exponential_function , color = RED , x_range = [- 3 , 3 ])
85
- exponential_label = axes .get_graph_label (exponential_graph , "y = 2^x/5" , direction = UR )
122
+ exponential_label = axes .get_graph_label (
123
+ exponential_graph , "y = 2^x/5" , direction = UR
124
+ )
86
125
self .play (Create (exponential_graph ), Write (exponential_label ))
87
126
self .wait ()
88
-
89
- self .play (FadeOut (axes ), FadeOut (linear_graph ), FadeOut (linear_label ), FadeOut (quadratic_graph ), FadeOut (quadratic_label ), FadeOut (exponential_graph ), FadeOut (exponential_label ))
127
+
128
+ self .play (
129
+ FadeOut (axes ),
130
+ FadeOut (linear_graph ),
131
+ FadeOut (linear_label ),
132
+ FadeOut (quadratic_graph ),
133
+ FadeOut (quadratic_label ),
134
+ FadeOut (exponential_graph ),
135
+ FadeOut (exponential_label ),
136
+ )
90
137
91
138
92
139
class GeometricShapes (Scene ):
93
140
def construct (self ):
94
141
# Create shapes
95
142
circle = Circle (radius = 2 , color = BLUE , fill_opacity = 0.5 ).shift (LEFT * 3 )
96
- triangle = Triangle (color = GREEN , fill_opacity = 0.5 ).shift (UP * 2 )
97
- rectangle = Rectangle (width = 4 , height = 3 , color = RED , fill_opacity = 0.5 ).shift (RIGHT * 3 + DOWN * 1 )
98
-
143
+ triangle = Triangle (color = GREEN , fill_opacity = 0.5 ).shift (UP * 2 )
144
+ rectangle = Rectangle (width = 4 , height = 3 , color = RED , fill_opacity = 0.5 ).shift (
145
+ RIGHT * 3 + DOWN * 1
146
+ )
147
+
99
148
self .play (Create (circle ), Create (triangle ), Create (rectangle ))
100
149
self .wait ()
101
150
@@ -105,15 +154,31 @@ def construct(self):
105
154
rectangle_area = MathTex ("Area = lw" ).next_to (rectangle , DOWN )
106
155
self .play (Write (circle_area ), Write (triangle_area ), Write (rectangle_area ))
107
156
self .wait ()
108
-
157
+
109
158
# Display perimeter
110
159
circle_perimeter = MathTex ("Perimeter = 2\pi r" ).next_to (circle_area , DOWN )
111
160
triangle_perimeter = MathTex ("Perimeter = a+b+c" ).next_to (triangle_area , DOWN )
112
- rectangle_perimeter = MathTex ("Perimeter = 2(l+w)" ).next_to (rectangle_area , DOWN )
113
- self .play (Write (circle_perimeter ), Write (triangle_perimeter ), Write (rectangle_perimeter ))
161
+ rectangle_perimeter = MathTex ("Perimeter = 2(l+w)" ).next_to (
162
+ rectangle_area , DOWN
163
+ )
164
+ self .play (
165
+ Write (circle_perimeter ),
166
+ Write (triangle_perimeter ),
167
+ Write (rectangle_perimeter ),
168
+ )
114
169
self .wait ()
115
-
116
- self .play (FadeOut (circle ), FadeOut (triangle ), FadeOut (rectangle ), FadeOut (circle_area ), FadeOut (triangle_area ), FadeOut (rectangle_area ), FadeOut (circle_perimeter ), FadeOut (triangle_perimeter ), FadeOut (rectangle_perimeter ))
170
+
171
+ self .play (
172
+ FadeOut (circle ),
173
+ FadeOut (triangle ),
174
+ FadeOut (rectangle ),
175
+ FadeOut (circle_area ),
176
+ FadeOut (triangle_area ),
177
+ FadeOut (rectangle_area ),
178
+ FadeOut (circle_perimeter ),
179
+ FadeOut (triangle_perimeter ),
180
+ FadeOut (rectangle_perimeter ),
181
+ )
117
182
118
183
119
184
class VectorVisualizations (Scene ):
@@ -135,18 +200,26 @@ def construct(self):
135
200
self .wait ()
136
201
137
202
# Vector addition
138
- vector_sum = Vector ([1 , 5 ], color = YELLOW ).shift (DOWN + RIGHT )
203
+ vector_sum = Vector ([1 , 5 ], color = YELLOW ).shift (DOWN + RIGHT )
139
204
sum_label = MathTex ("a+b" ).next_to (vector_sum , UR )
140
205
self .play (Create (vector_sum ), Write (sum_label ))
141
206
self .wait ()
142
207
143
208
# Scalar multiplication
144
- vector_scaled = Vector ([4 , 4 ], color = RED ).shift (DOWN * 2 )
209
+ vector_scaled = Vector ([4 , 4 ], color = RED ).shift (DOWN * 2 )
145
210
scaled_label = MathTex ("2a" ).next_to (vector_scaled , UR )
146
211
self .play (Transform (vector_a , vector_scaled ), Write (scaled_label ))
147
212
self .wait ()
148
-
149
- self .play (FadeOut (axes ), FadeOut (vector_a ), FadeOut (vector_b ), FadeOut (vector_sum ), FadeOut (sum_label ), FadeOut (vector_scaled ), FadeOut (scaled_label ))
213
+
214
+ self .play (
215
+ FadeOut (axes ),
216
+ FadeOut (vector_a ),
217
+ FadeOut (vector_b ),
218
+ FadeOut (vector_sum ),
219
+ FadeOut (sum_label ),
220
+ FadeOut (vector_scaled ),
221
+ FadeOut (scaled_label ),
222
+ )
150
223
151
224
152
225
class ProbabilityDistributions (Scene ):
@@ -158,31 +231,38 @@ def construct(self):
158
231
x_length = 8 ,
159
232
y_length = 4 ,
160
233
axis_config = {"include_numbers" : True },
161
- ).shift (UP * 2 )
234
+ ).shift (UP * 2 )
162
235
self .play (Create (axes_uniform ))
163
236
164
237
bars = []
165
238
for i in range (10 ):
166
- bar = Rectangle (width = 0.8 , height = 0.8 , color = BLUE , fill_opacity = 0.5 ).move_to (axes_uniform .c2p (i + 0.5 , 0.4 ))
239
+ bar = Rectangle (
240
+ width = 0.8 , height = 0.8 , color = BLUE , fill_opacity = 0.5
241
+ ).move_to (axes_uniform .c2p (i + 0.5 , 0.4 ))
167
242
bars .append (bar )
168
243
self .play (Create (bar ), run_time = 0.1 )
169
244
self .wait ()
170
-
245
+
171
246
# Normal distribution
172
247
axes_normal = Axes (
173
248
x_range = [- 5 , 5 , 1 ],
174
249
y_range = [0 , 0.5 , 0.1 ],
175
- x_length = 8 ,
250
+ x_length = 8 ,
176
251
y_length = 4 ,
177
252
axis_config = {"include_numbers" : True },
178
- ).shift (DOWN * 2 )
253
+ ).shift (DOWN * 2 )
179
254
self .play (Create (axes_normal ))
180
-
255
+
181
256
def normal_distribution (x ):
182
- return 0.4 * np .exp (- x ** 2 / 2 )
183
-
257
+ return 0.4 * np .exp (- ( x ** 2 ) / 2 )
258
+
184
259
normal_curve = axes_normal .plot (normal_distribution , color = RED )
185
260
self .play (Create (normal_curve ))
186
261
self .wait ()
187
-
188
- self .play (FadeOut (axes_uniform ),* [FadeOut (bar ) for bar in bars ], FadeOut (axes_normal ), FadeOut (normal_curve ))
262
+
263
+ self .play (
264
+ FadeOut (axes_uniform ),
265
+ * [FadeOut (bar ) for bar in bars ],
266
+ FadeOut (axes_normal ),
267
+ FadeOut (normal_curve ),
268
+ )
0 commit comments