Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Some simple eoc cleanup

Grant Sandersonad25f6532799
diff --git a/eoc/chapter1.py b/eoc/chapter1.py
index 128d8afdd..31d3e63e1 100644
--- a/eoc/chapter1.py
+++ b/eoc/chapter1.py
@@ -2754,6 +2754,7 @@ class EndScreen(PiCreatureScene):
}
def construct(self):
words = TextMobject("Clicky stuffs")
+ words.scale(1.5)
words.next_to(self.pi_creature, UP)
words.to_edge(UP)
diff --git a/eoc/chapter10.py b/eoc/chapter10.py
index 9569aed42..7affd76da 100644
--- a/eoc/chapter10.py
+++ b/eoc/chapter10.py
@@ -197,6 +197,11 @@ class Pendulum(ReconfigurableScene):
"radius" : 4,
"weight_radius" : 0.2,
"angle" : np.pi/6,
+ "approx_tex" : [
+ "\\approx 1 - ", "{\\theta", "^2", "\\over", "2}"
+ ],
+ "leave_original_cosine" : False,
+ "perform_substitution" : True,
}
def construct(self):
self.draw_pendulum()
@@ -206,7 +211,6 @@ class Pendulum(ReconfigurableScene):
self.substitute_approximation()
self.show_confusion()
-
def draw_pendulum(self):
pendulum = self.get_pendulum()
ceiling = self.get_ceiling()
@@ -295,6 +299,10 @@ class Pendulum(ReconfigurableScene):
cosine.generate_target()
cosine.save_state()
cosine.target.next_to(morty, UP)
+ if self.leave_original_cosine:
+ cosine_copy = cosine.copy()
+ self.add(cosine_copy)
+ self.one_minus.add(cosine_copy)
self.play(FadeIn(morty))
self.play(
@@ -330,6 +338,8 @@ class Pendulum(ReconfigurableScene):
morty.change, "pondering", cosine_approx
)
self.dither()
+ if not self.perform_substitution:
+ return
self.play(
ApplyMethod(
cosine_approx.theta_squared_over_two.copy().next_to,
@@ -466,11 +476,9 @@ class Pendulum(ReconfigurableScene):
return arc, theta
def get_cosine_approx(self):
- approx = TexMobject(
- "\\approx 1 - ", "{\\theta", "^2", "\\over", "2}"
- )
+ approx = TexMobject(*self.approx_tex)
approx.highlight_by_tex("theta", YELLOW)
- approx.theta_squared_over_two = VGroup(*approx[-4:])
+ approx.theta_squared_over_two = VGroup(*approx[1:5])
return approx
@@ -484,6 +492,18 @@ class Pendulum(ReconfigurableScene):
def swing_rate_func(self, t):
return (1-np.cos(np.pi*t))/2.0
+class PendulumWithBetterApprox(Pendulum):
+ CONFIG = {
+ "approx_tex" : [
+ "\\approx 1 - ", "{\\theta", "^2", "\\over", "2}",
+ "+", "{\\theta", "^4", "\\over", "24}"
+ ],
+ "leave_original_cosine" : True,
+ "perform_substitution" : False,
+ }
+ def show_confusion(self):
+ pass
+
class ExampleApproximationWithCos(ExampleApproximationWithSine):
CONFIG = {
"function" : np.cos,
@@ -1852,9 +1872,56 @@ class HigherTermsDontMessUpLowerTerms(Scene):
self.play(Write(equals_zero))
self.dither(3)
+class EachTermControlsOneDerivative(Scene):
+ def construct(self):
+ colors = CubicAndQuarticApproximations.CONFIG["colors"]
+ polynomial = TexMobject(
+ "P(x) = ", "c_0", "+", "c_1", "x", *it.chain(*[
+ ["+", "c_%d"%n, "x^%d"%n]
+ for n in range(2, 5)
+ ])
+ )
+ consts = polynomial.get_parts_by_tex("c")
+ deriv_words = VGroup(*[
+ TextMobject("Controls \\\\ $%s(0)$"%tex)
+ for tex in [
+ "P",
+ "\\frac{dP}{dx}",
+ ] + [
+ "\\frac{d^%d P}{dx^%d}"%(n, n)
+ for n in range(2, 5)
+ ]
+ ])
+ deriv_words.arrange_submobjects(
+ RIGHT,
+ buff = LARGE_BUFF,
+ aligned_edge = UP
+ )
+ deriv_words.scale_to_fit_width(2*SPACE_WIDTH - MED_LARGE_BUFF)
+ deriv_words.to_edge(UP)
+
+ for const, deriv, color in zip(consts, deriv_words, colors):
+ for mob in const, deriv:
+ mob.highlight(color)
+ arrow = Arrow(
+ const.get_top(),
+ deriv.get_bottom(),
+ # buff = SMALL_BUFF,
+ color = color
+ )
+ deriv.arrow = arrow
+
+ self.add(polynomial)
+ for deriv in deriv_words:
+ self.play(
+ ShowCreation(deriv.arrow),
+ FadeIn(deriv)
+ )
+ self.dither()
+
class ApproximateNearNewPoint(CubicAndQuarticApproximations):
CONFIG = {
- "target_approx_centers" : [-np.pi/2, np.pi/2, np.pi],
+ "target_approx_centers" : [np.pi/2, np.pi],
}
def construct(self):
self.setup_axes()
@@ -1962,6 +2029,14 @@ class ApproximateNearNewPoint(CubicAndQuarticApproximations):
])
return self.get_graph(func, color = GREEN)
+class OnAPhilosophicalLevel(TeacherStudentsScene):
+ def construct(self):
+ self.teacher_says(
+ "And on a \\\\ philosophical level",
+ run_time = 1
+ )
+ self.dither(3)
+
class TranslationOfInformation(CubicAndQuarticApproximations):
def construct(self):
self.add_background()
@@ -1989,7 +2064,7 @@ class TranslationOfInformation(CubicAndQuarticApproximations):
deriv_info.next_to(ORIGIN, LEFT, LARGE_BUFF)
deriv_info.to_edge(UP)
output_info = TextMobject(
- "Output \\\\ information \\\\ near that piont"
+ "Output \\\\ information \\\\ near that point"
)
output_info.next_to(ORIGIN, RIGHT, LARGE_BUFF)
output_info.to_edge(UP)
@@ -2419,6 +2494,18 @@ class TranslationOfInformation(CubicAndQuarticApproximations):
return result
+class ThisIsAStandardFormula(TeacherStudentsScene):
+ def construct(self):
+ self.teacher_says(
+ "You will see this \\\\ in your texts",
+ run_time = 1
+ )
+ self.change_student_modes(
+ *["sad"]*3,
+ look_at_arg = SPACE_HEIGHT*UP
+ )
+ self.dither(2)
+
class ExpPolynomial(TranslationOfInformation, ExampleApproximationWithExp):
CONFIG = {
"x_tick_frequency" : 1,
@@ -2569,12 +2656,23 @@ class ShowSecondTerm(TeacherStudentsScene):
words = TextMobject("Geometric view")
words.next_to(box, UP)
- self.play(Write(polynomial))
+ self.teacher_says(
+ "Now for \\\\ something fun!",
+ target_mode = "hooray"
+ )
+ self.dither(2)
+ self.play(
+ RemovePiCreatureBubble(
+ self.teacher,
+ target_mode = "raise_right_hand"
+ ),
+ Write(polynomial)
+ )
self.play(
ShowCreation(box),
FadeIn(words),
- self.teacher.change_mode, "raise_right_hand"
)
+ self.change_student_modes(*["pondering"]*3)
self.dither(3)
class SecondTermIntuition(AreaIsDerivative):
@@ -2899,6 +2997,20 @@ class SecondTermIntuition(AreaIsDerivative):
self.play(FadeIn(VGroup(*analytic_taylor[5:])))
self.dither(3)
+class EachTermHasMeaning(TeacherStudentsScene):
+ def construct(self):
+ self.get_pi_creatures().scale_in_place(0.8).shift(UP)
+ self.teacher_says(
+ "Each term \\\\ has meaning!",
+ target_mode = "hooray",
+ bubble_kwargs = {"height" : 3, "width" : 4}
+ )
+ self.change_student_modes(
+ *["thinking"]*3,
+ look_at_arg = 4*UP
+ )
+ self.dither(3)
+
class AskAboutInfiniteSum(TeacherStudentsScene):
def construct(self):
self.ask_question()
@@ -3513,9 +3625,70 @@ class MoreToBeSaid(TeacherStudentsScene):
self.play(ShowCreation(rect))
self.dither(4)
+class Chapter10Thanks(PatreonThanks):
+ CONFIG = {
+ "specific_patrons" : [
+ "Ali Yahya",
+ "CrypticSwarm",
+ "Kaustuv DeBiswas",
+ "Kathryn Schmiedicke",
+ "Karan Bhargava",
+ "Ankit Agarwal",
+ "Yu Jun",
+ "Dave Nicponski",
+ "Damion Kistler",
+ "Juan Benet",
+ "Othman Alikhan",
+ "Markus Persson",
+ "Joseph John Cox",
+ "Dan Buchoff",
+ "Derek Dai",
+ "Luc Ritchie",
+ "Ahmad Bamieh",
+ "Mark Govea",
+ "Zac Wentzell",
+ "Robert Teed",
+ "Jason Hise",
+ "Meshal Alshammari",
+ "Bernd Sing",
+ "Nils Schneider",
+ "James Thornton",
+ "Mustafa Mahdi",
+ "Jonathan Eppele",
+ "Mathew Bramson",
+ "Jerry Ling",
+ "Vecht",
+ "Shimin Kuang",
+ "Rish Kundalia",
+ "Achille Brighton",
+ "Ripta Pasay",
+ ],
+ }
+class Thumbnail(ExampleApproximationWithSine):
+ CONFIG = {
+ "graph_origin" : DOWN,
+ "x_axis_label" : "",
+ "y_axis_label" : "",
+ "x_axis_width" : 14,
+ "graph_stroke_width" : 8,
+ }
+ def construct(self):
+ self.setup_axes()
-
+ cos_graph = self.get_graph(np.cos)
+ cos_graph.set_stroke(BLUE, self.graph_stroke_width)
+ quad_graph = self.get_graph(taylor_approximation(np.cos, 2))
+ quad_graph.set_stroke(GREEN, self.graph_stroke_width)
+ quartic = self.get_graph(taylor_approximation(np.cos, 4))
+ quartic.set_stroke(PINK, self.graph_stroke_width)
+ self.add(cos_graph, quad_graph, quartic)
+
+ title = TextMobject("Taylor Series")
+ title.scale_to_fit_width(1.5*SPACE_WIDTH)
+ title.add_background_rectangle()
+ title.to_edge(UP)
+ self.add(title)
diff --git a/eoc/chapter2.py b/eoc/chapter2.py
index 60b46ddf5..a79c128d3 100644
--- a/eoc/chapter2.py
+++ b/eoc/chapter2.py
@@ -2533,7 +2533,7 @@ class NextVideos(TeacherStudentsScene):
self.dither(2)
self.change_student_modes(*["thinking"]*3)
self.dither(3)
-
+
class Chapter2PatreonThanks(PatreonThanks):
CONFIG = {
"specific_patrons" : [
diff --git a/eoc/chapter3.py b/eoc/chapter3.py
index e2244ab07..857e8aca6 100644
--- a/eoc/chapter3.py
+++ b/eoc/chapter3.py
@@ -2788,6 +2788,34 @@ class Chapter3PatreonThanks(PatreonThanks):
]
}
+class Promotion(PiCreatureScene):
+ CONFIG = {
+ "seconds_to_blink" : 5,
+ }
+ def construct(self):
+ url = TextMobject("https://brilliant.org/3b1b/")
+ url.to_corner(UP+LEFT)
+
+ rect = Rectangle(height = 9, width = 16)
+ rect.scale_to_fit_height(5.5)
+ rect.next_to(url, DOWN)
+ rect.to_edge(LEFT)
+
+ self.play(
+ Write(url),
+ self.pi_creature.change, "raise_right_hand"
+ )
+ self.play(ShowCreation(rect))
+ self.dither(2)
+ self.change_mode("thinking")
+ self.dither()
+ self.look_at(url)
+ self.dither(10)
+ self.change_mode("happy")
+ self.dither(10)
+ self.change_mode("raise_right_hand")
+ self.dither(10)
+
class Thumbnail(NudgeSideLengthOfCube):
def construct(self):
self.introduce_cube()
diff --git a/eoc/chapter4.py b/eoc/chapter4.py
index 446e70290..60e07dd32 100644
--- a/eoc/chapter4.py
+++ b/eoc/chapter4.py
@@ -2270,7 +2270,8 @@ class Chapter4Thanks(PatreonThanks):
"Kirk Werklund",
"Ripta Pasay",
"Felipe Diniz",
- ]
+ ],
+ "patron_group_size" : 8,
}
class Thumbnail(IntroduceProductAsArea):