Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Some calc cleanup

Grant Sanderson6a88ff207cea
diff --git a/eoc/chapter5.py b/eoc/chapter5.py
index 0671ad38d..814afa91e 100644
--- a/eoc/chapter5.py
+++ b/eoc/chapter5.py
@@ -1608,6 +1608,65 @@ class CompareWaysToWriteExponentials(GraphScene):
self.dither(2)
self.dither()
+class ManyExponentialForms(TeacherStudentsScene):
+ def construct(self):
+ lhs = TexMobject("2", "^t")
+ rhs_list = [
+ TexMobject("=", "%s^"%tex, "{(%.5f\\dots)"%log, "t}")
+ for tex, log in [
+ ("e", np.log(2)),
+ ("\\pi", np.log(2)/np.log(np.pi)),
+ ("42", np.log(2)/np.log(42)),
+ ]
+ ]
+ group = VGroup(lhs, *rhs_list)
+ group.arrange_submobjects(RIGHT)
+ group.scale_to_fit_width(2*SPACE_WIDTH - LARGE_BUFF)
+ group.next_to(self.get_pi_creatures(), UP, 2*LARGE_BUFF)
+ for part in group:
+ part.highlight_by_tex("t", YELLOW)
+ const = part.get_part_by_tex("dots")
+ if const:
+ const.highlight(BLUE)
+ brace = Brace(const, UP)
+ log = brace.get_text(
+ "$\\log_{%s}(2)$"%part[1].get_tex_string()[:-1]
+ )
+ log.highlight(BLUE)
+ part.add(brace, log)
+ exp = VGroup(*rhs_list[0][1:4])
+ rect = BackgroundRectangle(group)
+
+ self.add(lhs, rhs_list[0])
+ self.dither()
+ for rhs in rhs_list[1:]:
+ self.play(FadeIn(
+ rhs,
+ run_time = 2,
+ submobject_mode = 'lagged_start'
+ ))
+ self.dither(2)
+ self.dither()
+ self.play(
+ FadeIn(rect),
+ exp.next_to, self.teacher, UP+LEFT,
+ self.teacher.change, "raise_right_hand",
+ )
+ self.play(*[
+ ApplyFunction(
+ lambda m : m.shift(SMALL_BUFF*UP).highlight(RED),
+ part,
+ run_time = 2,
+ rate_func = squish_rate_func(there_and_back, a, a+0.3)
+ )
+ for part, a in zip(exp[1], np.linspace(0, 0.7, len(exp[1])))
+ ])
+ self.change_student_modes(
+ *["pondering"]*3,
+ look_at_arg = exp
+ )
+ self.dither(3)
+
class TooManySymbols(TeacherStudentsScene):
def construct(self):
self.student_says(
@@ -1951,7 +2010,17 @@ class ExpPatreonThanks(PatreonThanks):
]
}
-class Thumbnail(Scene):
+class Thumbnail(GraphOfTwoToT):
+ CONFIG = {
+ "x_axis_label" : "",
+ "y_axis_label" : "",
+ "x_labeled_nums" : None,
+ "y_labeled_nums" : None,
+ "y_max" : 32,
+ "y_tick_frequency" : 4,
+ "graph_origin" : 3*DOWN + 5*LEFT,
+ "x_axis_width" : 12,
+ }
def construct(self):
derivative = TexMobject(
"\\frac{d(a^t)}{dt} =", "a^t \\ln(a)"
@@ -1961,32 +2030,36 @@ class Thumbnail(Scene):
derivative[0][2].highlight(BLUE)
derivative[1][0].highlight(BLUE)
derivative[1][5].highlight(BLUE)
- derivative.scale(3)
- # derivative.to_edge(UP)
- derivative.shift(DOWN)
+ derivative.scale(2)
+ derivative.add_background_rectangle()
+ derivative.to_corner(DOWN+RIGHT, buff = MED_SMALL_BUFF)
- brace = Brace(Line(LEFT, RIGHT), UP)
- brace.scale_to_fit_width(derivative[1].get_width())
- brace.next_to(derivative[1], UP)
- question = TextMobject("Why?")
- question.scale(2.5)
- question.next_to(brace, UP)
+ # brace = Brace(Line(LEFT, RIGHT), UP)
+ # brace.scale_to_fit_width(derivative[1].get_width())
+ # brace.next_to(derivative[1], UP)
+ # question = TextMobject("Why?")
+ # question.scale(2.5)
+ # question.next_to(brace, UP)
# randy = Randolph()
# randy.scale(1.3)
# randy.next_to(ORIGIN, LEFT).to_edge(DOWN)
# randy.change_mode("pondering")
- # question = TextMobject("What is $e\\,$?")
- # e = question[-2]
- # e.scale(1.2, about_point = e.get_bottom())
- # e.highlight(BLUE)
- # question.scale(1.7)
- # question.next_to(randy, RIGHT, aligned_edge = UP)
- # question.shift(DOWN)
+ question = TextMobject("What is $e\\,$?")
+ e = question[-2]
+ e.scale(1.2, about_point = e.get_bottom())
+ e.highlight(BLUE)
+ question.scale(3)
+ question.add_background_rectangle()
+ question.to_edge(UP)
# randy.look_at(question)
- self.add(derivative, brace, question)
+ self.setup_axes()
+ graph = self.get_graph(np.exp)
+ graph.set_stroke(YELLOW, 8)
+
+ self.add(graph, question, derivative)
diff --git a/eoc/chapter7.py b/eoc/chapter7.py
index 59f57913e..a5d27322c 100644
--- a/eoc/chapter7.py
+++ b/eoc/chapter7.py
@@ -2926,7 +2926,6 @@ class Chapter7PatreonThanks(PatreonThanks):
"Kathryn Schmiedicke",
"Nathan Pellegrin",
"Karan Bhargava",
- "Justin Helps",
"Ankit Agarwal",
"Yu Jun",
"Dave Nicponski",
@@ -2939,7 +2938,6 @@ class Chapter7PatreonThanks(PatreonThanks):
"Derek Dai",
"Joseph John Cox",
"Luc Ritchie",
- "Mustafa Mahdi",
"Daan Smedinga",
"Jonathan Eppele",
"Albert Nguyen",
diff --git a/eoc/chapter8.py b/eoc/chapter8.py
index 38f42a707..1d99aaa08 100644
--- a/eoc/chapter8.py
+++ b/eoc/chapter8.py
@@ -2783,14 +2783,11 @@ class Thumbnail(Chapter1Thumbnail):
x_max = 4,
dx = 0.25,
)
- # words = TextMobject("""
- # Essence of
- # calculus
- # """)
- # words.scale_to_fit_width(9)
- # words.to_edge(UP)
-
- self.add(graph, rects)
+ words = TextMobject("Integrals")
+ words.scale_to_fit_width(8)
+ words.to_edge(UP)
+
+ self.add(graph, rects, words)
diff --git a/eoc/chapter9.py b/eoc/chapter9.py
index e838680f7..83c763511 100644
--- a/eoc/chapter9.py
+++ b/eoc/chapter9.py
@@ -2078,25 +2078,110 @@ class Chapter9PatreonThanks(PatreonThanks):
],
}
-class Thumbnail(AverageOfSineStart):
+class Thumbnail(GraphScene):
+ CONFIG = {
+ "x_min" : -0.2,
+ "x_max" : 3.5,
+ "x_leftmost_tick" : 0,
+ "x_tick_frequency" : np.pi/4,
+ "x_axis_label" : "",
+ "y_min" : -0.75,
+ "y_max" : 0.75,
+ "y_axis_height" : 4.5,
+ "y_tick_frequency" : 0.25,
+ "y_axis_label" : ""
+ }
def construct(self):
- # self.setup_axes()
- # self.add_graph()
- # self.add(self.get_riemann_rectangles(
- # self.graph,
- # x_min = self.bounds[0],
- # x_max = self.bounds[1],
- # dx = 0.01,
- # stroke_width = 0,
- # ))
- tex_mob = TexMobject(
- "{1 \\over", "b", "-", "a}",
- "\\int", "^b", "_a", "f(x)", "\\,dx"
- )
- tex_mob.scale_to_fit_height(SPACE_HEIGHT)
- for tex, color in zip("abf", [GREEN, YELLOW, BLUE]):
- tex_mob.highlight_by_tex(tex, color)
- self.add(tex_mob)
+ self.setup_axes()
+ self.remove(self.axes)
+
+ sine = self.get_graph(np.sin)
+ rects = self.get_riemann_rectangles(
+ sine,
+ x_min = 0,
+ x_max = np.pi,
+ dx = 0.01,
+ stroke_width = 0,
+ )
+ sine.add_to_back(rects)
+ sine.add(self.axes.copy())
+ sine.to_corner(UP+LEFT, buff = SMALL_BUFF)
+ sine.scale(0.9)
+
+ area = TextMobject("Area")
+ area.scale(3)
+ area.move_to(rects)
+
+ cosine = self.get_graph(lambda x : -np.cos(x))
+ cosine.set_stroke(GREEN, 8)
+ line = self.get_secant_slope_group(
+ 0.75*np.pi, cosine,
+ dx = 0.01
+ ).secant_line
+ line.set_stroke(PINK, 7)
+ cosine.add(line)
+ cosine.add(self.axes.copy())
+ cosine.scale(0.7)
+ cosine.to_corner(DOWN+RIGHT, buff = MED_SMALL_BUFF)
+
+ slope = TextMobject("Slope")
+ slope.scale(3)
+ # slope.next_to(cosine, LEFT, buff = 0)
+ # slope.to_edge(DOWN)
+ slope.to_corner(DOWN+RIGHT)
+
+ double_arrow = DoubleArrow(
+ area.get_bottom(),
+ slope.get_left(),
+ color = YELLOW,
+ tip_length = 0.75,
+ buff = MED_LARGE_BUFF
+ )
+ double_arrow.set_stroke(width = 18)
+
+ triangle = Polygon(
+ ORIGIN, UP, UP+RIGHT,
+ stroke_width = 0,
+ fill_color = BLUE_E,
+ fill_opacity = 0.5,
+ )
+ triangle.stretch_to_fit_width(2*SPACE_WIDTH)
+ triangle.stretch_to_fit_height(2*SPACE_HEIGHT)
+ triangle.to_corner(UP+LEFT, buff = 0)
+
+ alt_triangle = triangle.copy()
+ alt_triangle.rotate(np.pi)
+ alt_triangle.set_fill(BLACK, 1)
+
+ self.add(
+ triangle, sine, area,
+ alt_triangle, cosine, slope,
+ double_arrow,
+ )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eoc/footnote.py b/eoc/footnote.py
new file mode 100644
index 000000000..ec9854986
--- /dev/null
+++ b/eoc/footnote.py
@@ -0,0 +1,357 @@
+from helpers import *
+import scipy
+import math
+
+from mobject.tex_mobject import TexMobject
+from mobject import Mobject
+from mobject.image_mobject import ImageMobject
+from mobject.vectorized_mobject import *
+
+from animation.animation import Animation
+from animation.transform import *
+from animation.simple_animations import *
+from animation.playground import *
+from topics.geometry import *
+from topics.characters import *
+from topics.functions import *
+from topics.fractals import *
+from topics.number_line import *
+from topics.combinatorics import *
+from topics.numerals import *
+from topics.three_dimensions import *
+from topics.objects import *
+from scene import Scene
+from scene.zoomed_scene import ZoomedScene
+from scene.reconfigurable_scene import ReconfigurableScene
+from camera import Camera
+from mobject.svg_mobject import *
+from mobject.tex_mobject import *
+
+from eoc.graph_scene import GraphScene
+
+class Introduce(TeacherStudentsScene):
+ def construct(self):
+ words = TextMobject("Next up is \\\\", "Taylor series")
+ words.highlight_by_tex("Taylor", BLUE)
+ derivs = VGroup(*[
+ TexMobject(
+ "{d", "^%d"%n, "f \\over dx", "^%d}"%n
+ ).highlight_by_tex(str(n), YELLOW)
+ for n in range(2, 5)
+ ])
+ derivs.next_to(self.teacher, UP, LARGE_BUFF)
+ second_deriv = derivs[0]
+ second_deriv.save_state()
+ card_dot = Dot(radius = SMALL_BUFF)
+ screen_rect = ScreenRectangle(height = 4)
+ screen_rect.move_to(3*UP, UP)
+
+ self.teacher_says(words, run_time = 2)
+ taylor_series = words.get_part_by_tex("Taylor").copy()
+ self.change_student_modes(*["happy"]*3)
+ self.play(
+ RemovePiCreatureBubble(
+ self.teacher,
+ target_mode = "raise_right_hand"
+ ),
+ taylor_series.next_to, screen_rect.copy(), UP,
+ ShowCreation(screen_rect)
+ )
+ card_dot.move_to(taylor_series)
+ card_dot.generate_target()
+ card_dot.target.set_fill(opacity = 0)
+ card_dot.target.to_edge(RIGHT, buff = MED_SMALL_BUFF)
+ arrow = Arrow(
+ taylor_series, card_dot.target,
+ buff = MED_SMALL_BUFF,
+ color = WHITE
+ )
+ self.play(FadeIn(second_deriv))
+ self.dither(2)
+ self.play(Transform(second_deriv, derivs[1]))
+ self.dither(2)
+ self.play(MoveToTarget(card_dot))
+ self.play(ShowCreation(arrow))
+ self.dither()
+ self.play(Transform(second_deriv, derivs[2]))
+ self.change_student_modes(*["erm"]*3)
+ self.dither()
+ self.play(second_deriv.restore)
+ self.dither(2)
+
+class SecondDerivativeGraphically(GraphScene):
+ CONFIG = {
+ "x1" : 0,
+ "x2" : 4,
+ "x3" : 8,
+ "y" : 4,
+ "deriv_color" : YELLOW,
+ "second_deriv_color" : GREEN,
+ }
+ def construct(self):
+ self.setup_axes()
+ self.draw_f()
+ self.show_derivative()
+ self.write_second_derivative()
+ self.show_curvature()
+ self.contrast_big_and_small_concavity()
+
+ def draw_f(self):
+ def func(x):
+ return 0.1*(x-self.x1)*(x-self.x2)*(x-self.x3) + self.y
+
+ graph = self.get_graph(func)
+ graph_label = self.get_graph_label(graph, "f(x)")
+
+ self.play(
+ ShowCreation(graph, run_time = 2),
+ Write(
+ graph_label,
+ run_time = 2,
+ rate_func = squish_rate_func(smooth, 0.5, 1)
+ )
+ )
+ self.dither()
+
+ self.graph = graph
+ self.graph_label = graph_label
+
+ def show_derivative(self):
+ deriv = TexMobject("\\frac{df}{dx}")
+ deriv.next_to(self.graph_label, DOWN, MED_LARGE_BUFF)
+ deriv.highlight(self.deriv_color)
+ ss_group = self.get_secant_slope_group(
+ 1, self.graph,
+ dx = 0.01,
+ secant_line_color = self.deriv_color
+ )
+
+ self.play(
+ Write(deriv),
+ *map(ShowCreation, ss_group)
+ )
+ self.animate_secant_slope_group_change(
+ ss_group, target_x = self.x3,
+ run_time = 5
+ )
+ self.dither()
+ self.animate_secant_slope_group_change(
+ ss_group, target_x = self.x2,
+ run_time = 3
+ )
+ self.dither()
+
+ self.ss_group = ss_group
+ self.deriv = deriv
+
+ def write_second_derivative(self):
+ second_deriv = TexMobject("\\frac{d^2 f}{dx^2}")
+ second_deriv.next_to(self.deriv, DOWN, MED_LARGE_BUFF)
+ second_deriv.highlight(self.second_deriv_color)
+ points = [
+ self.input_to_graph_point(x, self.graph)
+ for x in self.x2, self.x3
+ ]
+ words = TextMobject("Change to \\\\ slope")
+ words.next_to(
+ center_of_mass(points), UP, 1.5*LARGE_BUFF
+ )
+ arrows = [
+ Arrow(words.get_bottom(), p, color = WHITE)
+ for p in points
+ ]
+
+ self.play(Write(second_deriv))
+ self.dither()
+ self.play(
+ Write(words),
+ ShowCreation(
+ arrows[0],
+ rate_func = squish_rate_func(smooth, 0.5, 1)
+ ),
+ run_time = 2
+ )
+ self.animate_secant_slope_group_change(
+ self.ss_group, target_x = self.x3,
+ run_time = 3,
+ added_anims = [
+ Transform(
+ *arrows,
+ run_time = 3,
+ path_arc = 0.75*np.pi
+ ),
+ ]
+ )
+ self.play(FadeOut(arrows[0]))
+ self.animate_secant_slope_group_change(
+ self.ss_group, target_x = self.x2,
+ run_time = 3,
+ )
+
+ self.second_deriv_words = words
+ self.second_deriv = second_deriv
+
+ def show_curvature(self):
+ positive_curve, negative_curve = [
+ self.get_graph(
+ self.graph.underlying_function,
+ x_min = x_min,
+ x_max = x_max,
+ color = color,
+ ).set_stroke(width = 6)
+ for x_min, x_max, color in [
+ (self.x2, self.x3, PINK),
+ (self.x1, self.x2, RED),
+ ]
+ ]
+ dot = Dot()
+ def get_dot_update_func(curve):
+ def update_dot(dot):
+ dot.move_to(curve.points[-1])
+ return dot
+ return update_dot
+
+ self.play(
+ ShowCreation(positive_curve, run_time = 3),
+ UpdateFromFunc(dot, get_dot_update_func(positive_curve))
+ )
+ self.play(FadeOut(dot))
+ self.dither()
+ self.animate_secant_slope_group_change(
+ self.ss_group, target_x = self.x3,
+ run_time = 4,
+ added_anims = [Animation(positive_curve)]
+ )
+
+ self.play(*map(FadeOut, [self.ss_group, positive_curve]))
+ self.animate_secant_slope_group_change(
+ self.ss_group, target_x = self.x1,
+ run_time = 0
+ )
+ self.play(FadeIn(self.ss_group))
+ self.play(
+ ShowCreation(negative_curve, run_time = 3),
+ UpdateFromFunc(dot, get_dot_update_func(negative_curve))
+ )
+ self.play(FadeOut(dot))
+ self.animate_secant_slope_group_change(
+ self.ss_group, target_x = self.x2,
+ run_time = 4,
+ added_anims = [Animation(negative_curve)]
+ )
+ self.dither(2)
+ self.play(*map(FadeOut, [
+ self.graph, self.ss_group,
+ negative_curve, self.second_deriv_words
+ ]))
+
+ def contrast_big_and_small_concavity(self):
+ colors = color_gradient([GREEN, WHITE], 3)
+ x0, y0 = 4, 2
+ graphs = [
+ self.get_graph(func, color = color)
+ for color, func in zip(colors, [
+ lambda x : 5*(x - x0)**2 + y0,
+ lambda x : 0.2*(x - x0)**2 + y0,
+ lambda x : (x-x0) + y0,
+ ])
+ ]
+ arg_rhs_list = [
+ TexMobject("(", str(x0), ")", "=", str(rhs))
+ for rhs in 5, 0.2, 0
+ ]
+ for graph, arg_rhs in zip(graphs, arg_rhs_list):
+ graph.ss_group = self.get_secant_slope_group(
+ x0-1, graph,
+ dx = 0.001,
+ secant_line_color = YELLOW
+ )
+ arg_rhs.move_to(self.second_deriv.get_center(), LEFT)
+ graph.arg_rhs = arg_rhs
+ graph = graphs[0]
+
+ v_line = DashedLine(*[
+ self.coords_to_point(x0, 0),
+ self.coords_to_point(x0, y0),
+ ])
+ input_label = TexMobject(str(x0))
+ input_label.next_to(v_line, DOWN)
+
+ self.play(ShowCreation(graph, run_time = 2))
+ self.play(
+ Write(input_label),
+ ShowCreation(v_line)
+ )
+ self.play(
+ ReplacementTransform(
+ input_label.copy(),
+ graph.arg_rhs.get_part_by_tex(str(x0))
+ ),
+ self.second_deriv.next_to, graph.arg_rhs.copy(), LEFT, SMALL_BUFF,
+ Write(VGroup(*[
+ submob
+ for submob in graph.arg_rhs
+ if submob is not graph.arg_rhs.get_part_by_tex(str(x0))
+ ]))
+ )
+ self.dither()
+ self.play(FadeIn(graph.ss_group))
+ self.animate_secant_slope_group_change(
+ graph.ss_group, target_x = x0 + 1,
+ run_time = 3,
+ )
+ self.play(FadeOut(graph.ss_group))
+ self.dither()
+ for new_graph in graphs[1:]:
+ self.play(Transform(graph, new_graph))
+ self.play(Transform(
+ graph.arg_rhs,
+ new_graph.arg_rhs,
+ ))
+ self.play(FadeIn(new_graph.ss_group))
+ self.animate_secant_slope_group_change(
+ new_graph.ss_group, target_x = x0 + 1,
+ run_time = 3,
+ )
+ self.play(FadeOut(new_graph.ss_group))
+
+class IntroduceNotation(TeacherStudentsScene):
+ def construct(self):
+
+
+ self.student_says(
+ "What's that notation?"
+ )
+ self.change_student_modes("confused", None, "confused")
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/topics/geometry.py b/topics/geometry.py
index 781ddd5b1..177050b41 100644
--- a/topics/geometry.py
+++ b/topics/geometry.py
@@ -369,6 +369,14 @@ class FullScreenFadeRectangle(Rectangle):
"fill_opacity" : 0.7,
}
+class ScreenRectangle(Rectangle):
+ CONFIG = {
+ "width_to_height_ratio" : 16.0/9.0,
+ "height" : 4,
+ }
+ def generate_points(self):
+ self.width = self.width_to_height_ratio * self.height
+ Rectangle.generate_points(self)
class PictureInPictureFrame(Rectangle):
CONFIG = {