Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

A few cleanups to eoc5 and eoc9

Grant Sanderson399a30874d6d
diff --git a/eoc/chapter5.py b/eoc/chapter5.py
index dcfcc18cf..7d4775dae 100644
--- a/eoc/chapter5.py
+++ b/eoc/chapter5.py
@@ -625,6 +625,106 @@ class SimpleGraphOfTwoToT(GraphOfTwoToT):
self.play(ShowCreation(pair))
self.dither()
+class FakeDiagram(TeacherStudentsScene):
+ def construct(self):
+ gs = GraphScene(skip_animations = True)
+ gs.setup_axes()
+ background_graph, foreground_graph = graphs = VGroup(*[
+ gs.get_graph(
+ lambda t : np.log(2)*2**t,
+ x_min = -8,
+ x_max = 2 + dx
+ )
+ for dx in 0.25, 0
+ ])
+ for graph in graphs:
+ end_point = graph.points[-1]
+ axis_point = end_point[0]*RIGHT + gs.graph_origin[1]*UP
+ for alpha in np.linspace(0, 1, 20):
+ point = interpolate(axis_point, graph.points[0], alpha)
+ graph.add_control_points(3*[point])
+ graph.set_stroke(width = 1)
+ graph.set_fill(opacity = 1)
+ graph.highlight(BLUE_D)
+ background_graph.highlight(YELLOW)
+ background_graph.set_stroke(width = 0.5)
+
+ graphs.next_to(self.teacher, UP+LEFT, LARGE_BUFF)
+ two_to_t = TexMobject("2^t")
+ two_to_t.next_to(
+ foreground_graph.get_corner(DOWN+RIGHT), UP+LEFT
+ )
+ corner_line = Line(*[
+ graph.get_corner(DOWN+RIGHT)
+ for graph in graphs
+ ])
+ dt_brace = Brace(corner_line, DOWN, buff = SMALL_BUFF)
+ dt = dt_brace.get_text("$dt$")
+
+ side_brace = Brace(graphs, RIGHT, buff = SMALL_BUFF)
+ deriv = side_brace.get_text("$\\frac{d(2^t)}{dt}$")
+
+ circle = Circle(color = RED)
+ circle.replace(deriv, stretch = True)
+ circle.scale_in_place(1.5)
+
+ words = TextMobject("Not a real explanation")
+ words.to_edge(UP)
+ arrow = Arrow(words.get_bottom(), two_to_t.get_corner(UP+LEFT))
+ arrow.highlight(WHITE)
+
+ diagram = VGroup(
+ graphs, two_to_t, dt_brace, dt,
+ side_brace, deriv, circle,
+ words, arrow
+ )
+
+ self.play(self.teacher.change_mode, "raise_right_hand")
+ self.play(
+ Animation(VectorizedPoint(graphs.get_right())),
+ DrawBorderThenFill(foreground_graph),
+ Write(two_to_t)
+ )
+ self.dither()
+ self.play(
+ ReplacementTransform(
+ foreground_graph.copy(),
+ background_graph,
+ ),
+ Animation(foreground_graph),
+ Animation(two_to_t),
+ GrowFromCenter(dt_brace),
+ Write(dt)
+ )
+ self.play(GrowFromCenter(side_brace))
+ self.play(Write(deriv, run_time = 2))
+ self.dither()
+
+ self.play(
+ ShowCreation(circle),
+ self.teacher.change_mode, "hooray"
+ )
+ self.change_student_modes(*["confused"]*3)
+ self.play(
+ Write(words),
+ ShowCreation(arrow),
+ self.teacher.change_mode, "shruggie"
+ )
+ self.dither(3)
+ self.play(
+ FadeOut(diagram),
+ *[
+ ApplyMethod(pi.change_mode, "plain")
+ for pi in self.get_pi_creatures()
+ ]
+ )
+ self.teacher_says(
+ "Let's think through\\\\ the algebra..."
+ )
+ self.dither(2)
+
+ self.diagram = diagram
+
class AnalyzeExponentRatio(PiCreatureScene):
CONFIG = {
"base" : 2,
@@ -924,12 +1024,83 @@ class ExponentRatioWithSeven(AnalyzeExponentRatio):
"base_str" : "7",
}
+class ExponentRatioWithEight(AnalyzeExponentRatio):
+ CONFIG = {
+ "base" : 8,
+ "base_str" : "8",
+ }
+
class ExponentRatioWithE(AnalyzeExponentRatio):
CONFIG = {
"base" : np.exp(1),
"base_str" : "e",
}
+class CompareTwoConstantToEightConstant(PiCreatureScene):
+ def construct(self):
+ two_deriv, eight_deriv = derivs = VGroup(*[
+ self.get_derivative_expression(base)
+ for base in 2, 8
+ ])
+
+ derivs.arrange_submobjects(
+ DOWN, buff = 1.5, aligned_edge = LEFT
+ )
+ derivs.to_edge(LEFT, LARGE_BUFF).shift(UP)
+ arrow = Arrow(*[deriv[-2] for deriv in derivs])
+ times_three = TexMobject("\\times 3")
+ times_three.next_to(arrow, RIGHT)
+
+ why = TextMobject("Why?")
+ why.next_to(self.pi_creature, UP, MED_LARGE_BUFF)
+
+ self.add(eight_deriv)
+ self.dither()
+ self.play(ReplacementTransform(
+ eight_deriv.copy(),
+ two_deriv
+ ))
+ self.dither()
+ self.play(ShowCreation(arrow))
+ self.play(
+ Write(times_three),
+ self.pi_creature.change_mode, "thinking"
+ )
+ self.dither(3)
+
+ self.play(
+ Animation(derivs),
+ Write(why),
+ self.pi_creature.change, "confused", derivs
+ )
+ self.dither()
+ for deriv in derivs:
+ for index in -5, -2:
+ self.play(Indicate(deriv[index]))
+ self.dither()
+ self.dither(2)
+
+ def get_derivative_expression(self, base):
+ base_str = str(base)
+ const_str = "%.4f\\dots"%np.log(base)
+ result = TexMobject(
+ "{d(", base_str, "^t", ")", "\\over", "dt}",
+ "=", base_str, "^t", "(", const_str, ")"
+ )
+ tex_color_paris = [
+ ("t", YELLOW),
+ ("dt", GREEN),
+ (const_str, BLUE)
+ ]
+ for tex, color in tex_color_paris:
+ result.highlight_by_tex(tex, color)
+ return result
+
+ def create_pi_creature(self):
+ self.pi_creature = Randolph().flip()
+ self.pi_creature.to_edge(DOWN).shift(3*RIGHT)
+ return self.pi_creature
+
class AskAboutConstantOne(TeacherStudentsScene):
def construct(self):
note = TexMobject(
@@ -962,6 +1133,8 @@ class AskAboutConstantOne(TeacherStudentsScene):
self.change_student_modes(*["confused"]*3)
self.dither(3)
+
+
class NaturalLog(Scene):
def construct(self):
expressions = VGroup(*map(self.get_expression, [2, 3, 7]))
diff --git a/eoc/chapter9.py b/eoc/chapter9.py
index 266164586..e838680f7 100644
--- a/eoc/chapter9.py
+++ b/eoc/chapter9.py
@@ -659,6 +659,15 @@ class FiniteSampleWithMoreSamplePoints(FiniteSample):
"dx" : 0.05
}
+class FeelsRelatedToAnIntegral(TeacherStudentsScene):
+ def construct(self):
+ self.student_says(
+ "Seems integral-ish...",
+ target_mode = "maybe"
+ )
+ self.play(self.teacher.change_mode, "happy")
+ self.dither(2)
+
class IntegralOfSine(FiniteSample):
CONFIG = {
"thin_dx" : 0.01,
@@ -979,6 +988,14 @@ class IntegralOfSine(FiniteSample):
run_time = 3
))
+class Approx31(Scene):
+ def construct(self):
+ tex = TexMobject("\\approx 31")
+ tex.scale_to_fit_width(2*SPACE_WIDTH - LARGE_BUFF)
+ tex.to_edge(LEFT)
+ self.play(Write(tex))
+ self.dither(3)
+
class LetsSolveThis(TeacherStudentsScene):
def construct(self):
expression = TexMobject(
@@ -1357,7 +1374,7 @@ class Antiderivative(AverageOfSineStart):
big_rect = Rectangle(
stroke_width = 0,
fill_color = BLACK,
- fill_opacity = 0.9,
+ fill_opacity = 0.75,
)
big_rect.scale_to_fit_width(2*SPACE_WIDTH)
big_rect.scale_to_fit_height(2*SPACE_HEIGHT)
@@ -1386,6 +1403,9 @@ class Antiderivative(AverageOfSineStart):
line.highlight(RED)
line.scale_in_place(1.2)
+ new_v_line = self.v_line.copy().highlight(RED)
+ new_h_line = self.h_line.copy().highlight(RED)
+
pi = TexMobject("\\pi")
pi.next_to(self.h_line, DOWN)
@@ -1393,7 +1413,12 @@ class Antiderivative(AverageOfSineStart):
FadeOut(self.rects),
FadeOut(self.area_two)
)
- self.play(Write(pi))
+ self.play(ShowCreation(new_v_line))
+ self.play(
+ ShowCreation(new_h_line),
+ Write(pi)
+ )
+ self.dither()
self.play(ShowCreation(line, run_time = 2))
self.dither()
@@ -1423,16 +1448,655 @@ class Antiderivative(AverageOfSineStart):
run_time = 6,
)
+class GeneralAverage(AverageOfContinuousVariable):
+ CONFIG = {
+ "bounds" : [1, 6],
+ "bound_colors" : [GREEN, RED],
+ "graph_origin" : 5*LEFT + 2*DOWN,
+ "num_rect_iterations" : 4,
+ "max_dx" : 0.25,
+ }
+ def construct(self):
+ self.setup_axes()
+ self.add_graph()
+ self.ask_about_average()
+ self.show_signed_area()
+ self.put_area_away()
+ self.show_finite_sample()
+ self.show_improving_samples()
+
+ def add_graph(self):
+ graph = self.get_graph(self.func)
+ graph_label = self.get_graph_label(graph, "f(x)")
+ v_lines = VGroup(*[
+ self.get_vertical_line_to_graph(
+ x, graph, line_class = DashedLine
+ )
+ for x in self.bounds
+ ])
+ for line, color in zip(v_lines, self.bound_colors):
+ line.highlight(color)
+ labels = map(TexMobject, "ab")
+ for line, label in zip(v_lines, labels):
+ vect = line.get_start()-line.get_end()
+ label.next_to(line, vect/np.linalg.norm(vect))
+ label.highlight(line.get_color())
+
+ self.y_axis_label_mob.shift(0.7*LEFT)
+
+ self.play(
+ ShowCreation(graph),
+ Write(
+ graph_label,
+ rate_func = squish_rate_func(smooth, 0.5, 1)
+ ),
+ run_time = 2
+ )
+ for line, label in zip(v_lines, labels):
+ self.play(
+ Write(label),
+ ShowCreation(line)
+ )
+ self.dither()
+
+ self.graph = graph
+ self.graph_label = graph_label
+ self.bounds_labels = labels
+ self.bound_lines = v_lines
+
+ def ask_about_average(self):
+ v_line = self.get_vertical_line_to_graph(
+ self.bounds[0], self.graph,
+ line_class = DashedLine,
+ color = WHITE
+ )
+ average = TextMobject("Average = ")
+ fraction = TexMobject(
+ "{\\displaystyle \\int", "^b", "_a", "f(x)", "\\,dx",
+ "\\over", "b", "-", "a}"
+ )
+ for color, tex in zip(self.bound_colors, "ab"):
+ fraction.highlight_by_tex(tex, color)
+ fraction.highlight_by_tex("displaystyle", WHITE)
+ integral = VGroup(*fraction[:5])
+ denominator = VGroup(*fraction[5:])
+ average.next_to(fraction.get_part_by_tex("over"), LEFT)
+ group = VGroup(average, fraction)
+ group.center().to_edge(UP).shift(LEFT)
+
+ self.count = 0
+ def next_v_line_anim():
+ target = self.bounds[0] if self.count%2 == 1 else self.bounds[1]
+ self.count += 1
+ return self.get_v_line_change_anim(
+ v_line, self.graph, target,
+ run_time = 4,
+ )
+
+ self.play(
+ next_v_line_anim(),
+ Write(average, run_time = 2),
+ )
+ self.play(
+ next_v_line_anim(),
+ Write(
+ VGroup(*[
+ fraction.get_part_by_tex(tex)
+ for tex in "int", "f(x)", "dx", "over"
+ ]),
+ rate_func = squish_rate_func(smooth, 0.25, 0.75),
+ run_time = 4
+ ),
+ *[
+ ReplacementTransform(
+ label.copy(),
+ fraction.get_part_by_tex(tex, substring = False),
+ run_time = 2
+ )
+ for label, tex in zip(
+ self.bounds_labels,
+ ["_a", "^b"]
+ )
+ ]
+ )
+ self.play(
+ next_v_line_anim(),
+ Write(
+ fraction.get_part_by_tex("-"),
+ run_time = 4,
+ rate_func = squish_rate_func(smooth, 0.5, 0.75),
+ ),
+ *[
+ ReplacementTransform(
+ label.copy(),
+ fraction.get_part_by_tex(tex, substring = False),
+ run_time = 4,
+ rate_func = squish_rate_func(smooth, 0.25, 0.75)
+ )
+ for label, tex in zip(
+ self.bounds_labels,
+ ["a}", "b"]
+ )
+ ]
+
+ )
+ self.play(next_v_line_anim())
+ self.play(FadeOut(v_line))
+
+ self.average_expression = VGroup(average, fraction)
+
+ def show_signed_area(self):
+ rect_list = self.get_riemann_rectangles_list(
+ self.graph,
+ self.num_rect_iterations,
+ max_dx = self.max_dx,
+ x_min = self.bounds[0],
+ x_max = self.bounds[1],
+ end_color = BLUE,
+ fill_opacity = 0.75,
+ stroke_width = 0.25,
+ )
+ rects = rect_list[0]
+ plus = TexMobject("+")
+ plus.move_to(self.coords_to_point(2, 2))
+ minus = TexMobject("-")
+ minus.move_to(self.coords_to_point(5.24, -1))
+
+ self.play(FadeIn(
+ rects,
+ run_time = 2,
+ submobject_mode = "lagged_start"
+ ))
+ for new_rects in rect_list[1:]:
+ self.transform_between_riemann_rects(rects, new_rects)
+ self.play(Write(plus))
+ self.play(Write(minus))
+ self.dither(2)
+
+ self.area = VGroup(rects, plus, minus)
+
+ def put_area_away(self):
+ self.play(
+ FadeOut(self.area),
+ self.average_expression.scale, 0.75,
+ self.average_expression.to_corner, DOWN+RIGHT,
+ )
+ self.dither()
+
+ def show_finite_sample(self):
+ v_lines = self.get_vertical_lines_to_graph(
+ self.graph,
+ x_min = self.bounds[0],
+ x_max = self.bounds[1],
+ color = GREEN
+ )
+ for line in v_lines:
+ if self.y_axis.point_to_number(line.get_end()) < 0:
+ line.highlight(RED)
+ line.save_state()
+
+ line_pair = VGroup(*v_lines[6:8])
+ brace = Brace(line_pair, DOWN)
+ dx = brace.get_text("$dx$")
+
+ num_samples = TextMobject("Num. samples")
+ approx = TexMobject("\\approx")
+ rhs = TexMobject("{b", "-", "a", "\\over", "dx}")
+ for tex, color in zip("ab", self.bound_colors):
+ rhs.highlight_by_tex(tex, color)
+ expression = VGroup(num_samples, approx, rhs)
+ expression.arrange_submobjects(RIGHT)
+ expression.next_to(self.y_axis, RIGHT)
+ rhs_copy = rhs.copy()
+
+ f_brace = Brace(line_pair, LEFT, buff = 0)
+ f_x = f_brace.get_text("$f(x)$")
+ add_up_f_over = TexMobject("\\text{Add up $f(x)$}", "\\over")
+ add_up_f_over.next_to(num_samples, UP)
+ add_up_f_over.to_edge(UP)
+
+
+ self.play(ShowCreation(v_lines, run_time = 2))
+ self.play(*map(Write, [brace, dx]))
+ self.dither()
+ self.play(Write(VGroup(num_samples, approx, *rhs[:-1])))
+ self.play(ReplacementTransform(
+ dx.copy(), rhs.get_part_by_tex("dx")
+ ))
+ self.dither(2)
+
+ self.play(
+ FadeIn(add_up_f_over),
+ *[
+ ApplyFunction(
+ lambda m : m.fade().set_stroke(width = 2),
+ v_line
+ )
+ for v_line in v_lines
+ ]
+ )
+ self.play(*[
+ ApplyFunction(
+ lambda m : m.restore().set_stroke(width = 5),
+ v_line,
+ run_time = 3,
+ rate_func = squish_rate_func(
+ there_and_back, a, a+0.2
+ )
+ )
+ for v_line, a in zip(v_lines, np.linspace(0, 0.8, len(v_lines)))
+ ])
+ self.play(*[vl.restore for vl in v_lines])
+ self.play(rhs_copy.next_to, add_up_f_over, DOWN)
+ self.dither(2)
+ frac_line = add_up_f_over[1]
+ self.play(
+ FadeOut(rhs_copy.get_part_by_tex("over")),
+ rhs_copy.get_part_by_tex("dx").next_to,
+ add_up_f_over[0], RIGHT, SMALL_BUFF,
+ frac_line.scale_about_point, 1.2, frac_line.get_left(),
+ frac_line.stretch_to_fit_height, frac_line.get_height(),
+ )
+ rhs_copy.remove(rhs_copy.get_part_by_tex("over"))
+ self.dither(2)
+
+ int_fraction = self.average_expression[1].copy()
+ int_fraction.generate_target()
+ int_fraction.target.next_to(add_up_f_over, RIGHT, LARGE_BUFF)
+ int_fraction.target.shift_onto_screen()
+ double_arrow = TexMobject("\\Leftrightarrow")
+ double_arrow.next_to(
+ int_fraction.target.get_part_by_tex("over"), LEFT
+ )
+
+ self.play(
+ MoveToTarget(int_fraction),
+ VGroup(add_up_f_over, rhs_copy).shift, 0.4*DOWN
+ )
+ self.play(Write(double_arrow))
+ self.play(*map(FadeOut, [
+ dx, brace, num_samples, approx, rhs
+ ]))
+ self.dither()
+
+ self.v_lines = v_lines
+
+ def show_improving_samples(self):
+ stroke_width = self.v_lines[0].get_stroke_width()
+ new_v_lines_list = [
+ self.get_vertical_lines_to_graph(
+ self.graph,
+ x_min = self.bounds[0],
+ x_max = self.bounds[1],
+ num_lines = len(self.v_lines)*(2**n),
+ color = GREEN,
+ stroke_width = float(stroke_width)/n
+ )
+ for n in range(1, 4)
+ ]
+ for new_v_lines in new_v_lines_list:
+ for line in new_v_lines:
+ if self.y_axis.point_to_number(line.get_end()) < 0:
+ line.highlight(RED)
+
+ for new_v_lines in new_v_lines_list:
+ self.play(Transform(
+ self.v_lines, new_v_lines,
+ run_time = 2,
+ submobject_mode = "lagged_start"
+ ))
+ self.dither()
+
+ ####
+
+ def func(self, x):
+ return 0.09*(x+1)*(x-4)*(x-8)
+
+class GeneralAntiderivative(GeneralAverage):
+ def construct(self):
+ self.force_skipping()
+ self.setup_axes()
+ self.add_graph()
+ self.revert_to_original_skipping_status()
+
+ self.fade_existing_graph()
+ self.add_fraction()
+ self.add_antiderivative_graph()
+ self.show_average_in_terms_of_F()
+ self.draw_slope()
+ self.show_tangent_line_slopes()
+
+ def fade_existing_graph(self):
+ self.graph.fade(0.3)
+ self.graph_label.fade(0.3)
+ self.bound_lines.fade(0.3)
+
+ def add_fraction(self):
+ fraction = TexMobject(
+ "{\\displaystyle \\int", "^b", "_a", "f(x)", "\\,dx",
+ "\\over", "b", "-", "a}"
+ )
+ for tex, color in zip("ab", self.bound_colors):
+ fraction.highlight_by_tex(tex, color)
+ fraction.highlight_by_tex("display", WHITE)
+
+ fraction.scale(0.8)
+ fraction.next_to(self.y_axis, RIGHT)
+ fraction.to_edge(UP, buff = MED_SMALL_BUFF)
+ self.add(fraction)
+
+ self.fraction = fraction
+
+ def add_antiderivative_graph(self):
+ x_max = 9.7
+ antideriv_graph = self.get_graph(
+ lambda x : scipy.integrate.quad(
+ self.graph.underlying_function,
+ 1, x
+ )[0],
+ color = YELLOW,
+ x_max = x_max,
+ )
+ antideriv_graph_label = self.get_graph_label(
+ antideriv_graph, "F(x)",
+ x_val = x_max
+ )
+
+ deriv = TexMobject(
+ "{dF", "\\over", "dx}", "(x)", "=", "f(x)"
+ )
+ deriv.highlight_by_tex("dF", antideriv_graph.get_color())
+ deriv.highlight_by_tex("f(x)", BLUE)
+ deriv.next_to(
+ antideriv_graph_label, DOWN, MED_LARGE_BUFF, LEFT
+ )
+
+ self.play(
+ ShowCreation(antideriv_graph),
+ Write(
+ antideriv_graph_label,
+ rate_func = squish_rate_func(smooth, 0.5, 1)
+ ),
+ run_time = 2,
+ )
+ self.dither()
+ self.play(Write(deriv))
+ self.dither()
+
+ self.antideriv_graph = antideriv_graph
+
+ def show_average_in_terms_of_F(self):
+ new_fraction = TexMobject(
+ "=",
+ "{F", "(", "b", ")", "-", "F", "(", "a", ")",
+ "\\over",
+ "b", "-", "a}"
+ )
+ for tex, color in zip("abF", self.bound_colors+[YELLOW]):
+ new_fraction.highlight_by_tex(tex, color)
+ new_fraction.next_to(
+ self.fraction.get_part_by_tex("over"), RIGHT,
+ align_using_submobjects = True
+ )
+
+ to_write = VGroup(*it.chain(*[
+ new_fraction.get_parts_by_tex(tex)
+ for tex in "=F()-"
+ ]))
+ to_write.remove(new_fraction.get_parts_by_tex("-")[-1])
+
+ numerator = VGroup(*new_fraction[1:10])
+ denominator = VGroup(*new_fraction[-3:])
+
+ self.play(Write(to_write))
+ self.play(*[
+ ReplacementTransform(
+ label.copy(),
+ new_fraction.get_part_by_tex(tex),
+ run_time = 2,
+ rate_func = squish_rate_func(smooth, a, a+0.7)
+ )
+ for label, tex, a in zip(
+ self.bounds_labels, "ab", [0, 0.3]
+ )
+ ])
+ self.dither()
+
+ self.show_change_in_height(numerator.copy())
+ self.shift_antideriv_graph_up_and_down()
+ self.play(Write(VGroup(*new_fraction[-4:])))
+ self.dither()
+
+ h_line_brace = Brace(self.h_line, DOWN)
+ denominator_copy = denominator.copy()
+ a_label = self.bounds_labels[0]
+ self.play(
+ GrowFromCenter(h_line_brace),
+ a_label.shift, 0.7*a_label.get_width()*LEFT,
+ a_label.shift, 2.2*a_label.get_height()*UP,
+ )
+ self.play(
+ denominator_copy.next_to, h_line_brace,
+ DOWN, SMALL_BUFF
+ )
+ self.dither(3)
+
+ def show_change_in_height(self, numerator):
+ numerator.add_to_back(BackgroundRectangle(numerator))
+ a_point, b_point = points = [
+ self.input_to_graph_point(x, self.antideriv_graph)
+ for x in self.bounds
+ ]
+ interim_point = b_point[0]*RIGHT + a_point[1]*UP
+
+ v_line = Line(b_point, interim_point)
+ h_line = Line(interim_point, a_point)
+ VGroup(v_line, h_line).highlight(WHITE)
+ brace = Brace(v_line, RIGHT, buff = SMALL_BUFF)
+
+ graph_within_bounds = self.get_graph(
+ self.antideriv_graph.underlying_function,
+ x_min = self.bounds[0],
+ x_max = self.bounds[1],
+ color = self.antideriv_graph.get_color()
+ )
+ b_label = self.bounds_labels[1]
+ self.play(
+ self.antideriv_graph.fade, 0.7,
+ Animation(graph_within_bounds)
+ )
+ self.play(
+ ShowCreation(v_line),
+ b_label.shift, b_label.get_width()*RIGHT,
+ b_label.shift, 1.75*b_label.get_height()*DOWN,
+ )
+ self.play(ShowCreation(h_line))
+ self.play(
+ numerator.scale, 0.75,
+ numerator.next_to, brace.copy(), RIGHT, SMALL_BUFF,
+ GrowFromCenter(brace),
+ )
+ self.dither(2)
+
+ self.antideriv_graph.add(
+ graph_within_bounds, v_line, h_line, numerator, brace
+ )
+ self.h_line = h_line
+ self.graph_points_at_bounds = points
+ def shift_antideriv_graph_up_and_down(self):
+ for vect in 2*UP, 3*DOWN, UP:
+ self.play(
+ self.antideriv_graph.shift, vect,
+ run_time = 2
+ )
+ self.dither()
+ def draw_slope(self):
+ line = Line(*self.graph_points_at_bounds)
+ line.highlight(PINK)
+ line.scale_in_place(1.3)
+ self.play(ShowCreation(line, run_time = 2))
+ self.dither()
+ def show_tangent_line_slopes(self):
+ ss_group = self.get_secant_slope_group(
+ x = self.bounds[0],
+ graph = self.antideriv_graph,
+ dx = 0.001,
+ secant_line_color = BLUE,
+ secant_line_length = 2,
+ )
+ self.play(*map(ShowCreation, ss_group))
+ for x in range(2):
+ for bound in reversed(self.bounds):
+ self.animate_secant_slope_group_change(
+ ss_group,
+ target_x = bound,
+ run_time = 5,
+ )
+class LastVideoWrapper(Scene):
+ def construct(self):
+ title = TextMobject("Chapter 8: Integrals")
+ title.to_edge(UP)
+ rect = Rectangle(height = 9, width = 16)
+ rect.set_stroke(WHITE)
+ rect.scale_to_fit_height(1.5*SPACE_HEIGHT)
+ rect.next_to(title, DOWN)
+ self.play(Write(title), ShowCreation(rect))
+ self.dither(5)
+class ASecondIntegralSensation(TeacherStudentsScene):
+ def construct(self):
+ finite_average = TexMobject("{1+5+4+2 \\over 4}")
+ numbers = VGroup(*finite_average[0:7:2])
+ plusses = VGroup(*finite_average[1:7:2])
+ denominator = VGroup(*finite_average[7:])
+ finite_average.to_corner(UP+LEFT)
+ finite_average.to_edge(LEFT)
+ continuum = UnitInterval(
+ color = GREY,
+ space_unit_to_num = 6
+ )
+ continuum.next_to(finite_average, RIGHT, 2)
+ line = Line(continuum.get_left(), continuum.get_right())
+ line.highlight(YELLOW)
+ arrow = Arrow(DOWN+RIGHT, ORIGIN)
+ arrow.next_to(line.get_start(), DOWN+RIGHT, SMALL_BUFF)
+
+ sigma_to_integral = TexMobject(
+ "\\sum \\Leftrightarrow \\int"
+ )
+ sigma_to_integral.next_to(
+ self.teacher.get_corner(UP+LEFT), UP, MED_LARGE_BUFF
+ )
+
+ self.teacher_says(
+ "A second integral \\\\ sensation"
+ )
+ self.change_student_modes(*["erm"]*3)
+ self.dither()
+ self.play(
+ Write(numbers),
+ RemovePiCreatureBubble(self.teacher),
+ )
+ self.change_student_modes(
+ *["pondering"]*3,
+ look_at_arg = numbers
+ )
+ self.play(Write(plusses))
+ self.dither()
+ self.play(Write(denominator))
+ self.dither()
+
+ self.change_student_modes(
+ *["confused"]*3,
+ look_at_arg = continuum,
+ added_anims = [Write(continuum, run_time = 2)]
+ )
+ self.play(ShowCreation(arrow))
+ arrow.save_state()
+ self.play(
+ arrow.next_to, line.copy().get_end(), DOWN+RIGHT, SMALL_BUFF,
+ ShowCreation(line),
+ run_time = 2
+ )
+ self.play(*map(FadeOut, [arrow]))
+ self.dither(2)
+ self.change_student_modes(
+ *["pondering"]*3,
+ look_at_arg = sigma_to_integral,
+ added_anims = [
+ Write(sigma_to_integral),
+ self.teacher.change_mode, "raise_right_hand"
+ ]
+ )
+ self.dither(3)
+
+class Chapter9PatreonThanks(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",
+ "Dan Buchoff",
+ "Derek Dai",
+ "Joseph John Cox",
+ "Luc Ritchie",
+ "Zac Wentzell",
+ "Robert Teed",
+ "Jason Hise",
+ "Meshal Alshammari",
+ "Bernd Sing",
+ "Nils Schneider",
+ "James Thornton",
+ "Mustafa Mahdi",
+ "Jonathan Eppele",
+ "Mathew Bramson",
+ "Jerry Ling",
+ "Mark Govea",
+ "Vecht",
+ "Shimin Kuang",
+ "Rish Kundalia",
+ "Achille Brighton",
+ "Ripta Pasay",
+ ],
+ }
+
+class Thumbnail(AverageOfSineStart):
+ 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)
diff --git a/mobject/tex_mobject.py b/mobject/tex_mobject.py
index 0f0129073..e776d1ca4 100644
--- a/mobject/tex_mobject.py
+++ b/mobject/tex_mobject.py
@@ -74,9 +74,17 @@ class TexMobject(SVGMobject):
result = result.replace("\n", " \\\\ \n ")
result = " ".join([self.alignment, result])
result = result.strip()
- result = self.remove_stray_braces(result)
+ result = self.modify_special_strings(result)
+
return result
+ def modify_special_strings(self, tex):
+ tex = self.remove_stray_braces(tex)
+ if tex == "\\over":
+ #fraction line needs something to be over
+ tex = "\\over\\,"
+ return tex
+
def remove_stray_braces(self, tex):
"""
Makes TexMobject resiliant to unmatched { at start
diff --git a/topics/common_scenes.py b/topics/common_scenes.py
index da78c0ceb..9ef53b026 100644
--- a/topics/common_scenes.py
+++ b/topics/common_scenes.py
@@ -107,20 +107,17 @@ class PatreonThanks(Scene):
patreon_logo.next_to(morty, UP, buff = MED_LARGE_BUFF)
patrons = map(TextMobject, self.specific_patrons)
- patron_groups = []
- index = 0
- counter = 0
- while index < len(patrons):
- next_index = index + self.patron_group_size
- group = VGroup(*patrons[index:next_index])
+ num_groups = float(len(patrons)) / self.patron_group_size
+ proportion_range = np.linspace(0, 1, num_groups + 1)
+ indices = (len(patrons)*proportion_range).astype('int')
+ patron_groups = [
+ VGroup(*patrons[i:j])
+ for i, j in zip(indices, indices[1:])
+ ]
+
+ for i, group in enumerate(patron_groups):
group.arrange_submobjects(DOWN, aligned_edge = LEFT)
- if counter%2 == 0:
- group.to_edge(LEFT)
- else:
- group.to_edge(RIGHT)
- patron_groups.append(group)
- index = next_index
- counter += 1
+ group.to_edge(LEFT if i%2 == 0 else RIGHT)
self.play(
morty.change_mode, "gracious",
diff --git a/topics/number_line.py b/topics/number_line.py
index 752c26a5d..c2b56fd02 100644
--- a/topics/number_line.py
+++ b/topics/number_line.py
@@ -114,7 +114,6 @@ class UnitInterval(NumberLine):
"number_at_center" : 0.5,
}
-
class Axes(VGroup):
CONFIG = {
"propogate_style_to_family" : True
@@ -125,7 +124,6 @@ class Axes(VGroup):
self.y_axis = NumberLine(**kwargs).rotate(np.pi/2)
self.add(self.x_axis, self.y_axis)
-
class NumberPlane(VMobject):
CONFIG = {
"color" : BLUE_D,