Skip to content

Commit c62d7b2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 579c51d commit c62d7b2

File tree

1 file changed

+116
-36
lines changed

1 file changed

+116
-36
lines changed

example_scenes/foundational_math.py

Lines changed: 116 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from manim import *
22

3+
34
class FoundationalMath(Scene):
45
def construct(self):
56
text = Tex("Foundational Math Concepts").scale(1.5)
@@ -13,7 +14,7 @@ def construct(self):
1314
# Create sets A and B
1415
circle_a = Circle(radius=2, color=BLUE, fill_opacity=0.5).shift(LEFT)
1516
circle_b = Circle(radius=2, color=GREEN, fill_opacity=0.5).shift(RIGHT)
16-
17+
1718
text_a = Tex("A").move_to(circle_a.get_center())
1819
text_b = Tex("B").move_to(circle_b.get_center())
1920

@@ -23,28 +24,62 @@ def construct(self):
2324
# Union of A and B
2425
union_text = Tex("A $\cup$ B").to_corner(UP)
2526
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+
)
2942
self.play(FadeIn(union_region_a), FadeIn(union_region_b), FadeIn(union_region))
3043
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+
3351
# Intersection of A and B
3452
intersection_text = Tex("A $\cap$ B").to_corner(UP)
3553
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+
)
3759
self.play(FadeIn(intersection_region))
3860
self.wait()
3961
self.play(FadeOut(intersection_region), FadeOut(intersection_text))
4062

4163
# Complement of A
4264
complement_text = Tex("A$^c$").to_corner(UP)
4365
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+
)
4573
self.play(FadeIn(complement_region))
4674
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+
)
4883

4984

5085
class FunctionGraphs(Scene):
@@ -73,29 +108,43 @@ def quadratic_function(x):
73108
return 0.2 * x**2 - 1
74109

75110
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+
)
77114
self.play(Create(quadratic_graph), Write(quadratic_label))
78115
self.wait()
79116

80117
# Exponential function
81118
def exponential_function(x):
82-
return 2**x/5
119+
return 2**x / 5
83120

84121
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+
)
86125
self.play(Create(exponential_graph), Write(exponential_label))
87126
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+
)
90137

91138

92139
class GeometricShapes(Scene):
93140
def construct(self):
94141
# Create shapes
95142
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+
99148
self.play(Create(circle), Create(triangle), Create(rectangle))
100149
self.wait()
101150

@@ -105,15 +154,31 @@ def construct(self):
105154
rectangle_area = MathTex("Area = lw").next_to(rectangle, DOWN)
106155
self.play(Write(circle_area), Write(triangle_area), Write(rectangle_area))
107156
self.wait()
108-
157+
109158
# Display perimeter
110159
circle_perimeter = MathTex("Perimeter = 2\pi r").next_to(circle_area, DOWN)
111160
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+
)
114169
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+
)
117182

118183

119184
class VectorVisualizations(Scene):
@@ -135,18 +200,26 @@ def construct(self):
135200
self.wait()
136201

137202
# Vector addition
138-
vector_sum = Vector([1, 5], color=YELLOW).shift(DOWN+RIGHT)
203+
vector_sum = Vector([1, 5], color=YELLOW).shift(DOWN + RIGHT)
139204
sum_label = MathTex("a+b").next_to(vector_sum, UR)
140205
self.play(Create(vector_sum), Write(sum_label))
141206
self.wait()
142207

143208
# Scalar multiplication
144-
vector_scaled = Vector([4, 4], color=RED).shift(DOWN*2)
209+
vector_scaled = Vector([4, 4], color=RED).shift(DOWN * 2)
145210
scaled_label = MathTex("2a").next_to(vector_scaled, UR)
146211
self.play(Transform(vector_a, vector_scaled), Write(scaled_label))
147212
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+
)
150223

151224

152225
class ProbabilityDistributions(Scene):
@@ -158,31 +231,38 @@ def construct(self):
158231
x_length=8,
159232
y_length=4,
160233
axis_config={"include_numbers": True},
161-
).shift(UP*2)
234+
).shift(UP * 2)
162235
self.play(Create(axes_uniform))
163236

164237
bars = []
165238
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))
167242
bars.append(bar)
168243
self.play(Create(bar), run_time=0.1)
169244
self.wait()
170-
245+
171246
# Normal distribution
172247
axes_normal = Axes(
173248
x_range=[-5, 5, 1],
174249
y_range=[0, 0.5, 0.1],
175-
x_length=8,
250+
x_length=8,
176251
y_length=4,
177252
axis_config={"include_numbers": True},
178-
).shift(DOWN*2)
253+
).shift(DOWN * 2)
179254
self.play(Create(axes_normal))
180-
255+
181256
def normal_distribution(x):
182-
return 0.4 * np.exp(-x**2 / 2)
183-
257+
return 0.4 * np.exp(-(x**2) / 2)
258+
184259
normal_curve = axes_normal.plot(normal_distribution, color=RED)
185260
self.play(Create(normal_curve))
186261
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

Comments
 (0)