Exemplo n.º 1
0
    def show_equation(self, chopped_cycloid, ref_mob):
        point2, point1 = chopped_cycloid.points[-2:]
        arc, theta, vert_line, tangent_line = self.get_marks(point1, point2)
        equation = TexMobject([
            "\\sin(\\theta)",
            "\\over \\sqrt{y}",
        ])
        sin, sqrt_y = equation.split()
        equation.next_to(ref_mob)
        const = TexMobject(" = \\text{constant}")
        const.next_to(equation)
        ceil_point = np.array(point1)
        ceil_point[1] = self.top[1]
        brace = Brace(Mobject(Point(point1), Point(ceil_point)), RIGHT)
        y_mob = TexMobject("y").next_to(brace)

        self.play(GrowFromCenter(sin), ShowCreation(arc),
                  GrowFromCenter(theta))
        self.play(ShowCreation(vert_line))
        self.play(ShowCreation(tangent_line))
        self.dither()
        self.play(GrowFromCenter(sqrt_y), GrowFromCenter(brace),
                  GrowFromCenter(y_mob))
        self.dither()
        self.play(Transform(Point(const.get_left()), const))
        self.dither()
Exemplo n.º 2
0
 def get_coordinate_labels(self, *numbers):
     result = VGroup()
     nudge = 0.1 * (DOWN + RIGHT)
     if len(numbers) == 0:
         numbers = range(-int(self.x_radius), int(self.x_radius) + 1)
         numbers += [
             complex(0, y) for y in range(-int(self.y_radius),
                                          int(self.y_radius) + 1)
         ]
     for number in numbers:
         point = self.number_to_point(number)
         num_str = str(number).replace("j", "i")
         if num_str.startswith("0"):
             num_str = "0"
         elif num_str in ["1i", "-1i"]:
             num_str = num_str.replace("1", "")
         num_mob = TexMobject(num_str)
         num_mob.add_background_rectangle()
         num_mob.scale(self.number_scale_factor)
         if complex(number).imag != 0:
             vect = DOWN + RIGHT
         else:
             vect = DOWN + RIGHT
         num_mob.next_to(point, vect, SMALL_BUFF)
         result.add(num_mob)
     return result
Exemplo n.º 3
0
    def get_x_slider(self, x):
        numbers = range(int(self.slider_x_max) + 1)
        line = NumberLine(
            x_min=0,
            x_max=self.slider_x_max,
            space_unit_to_num=float(self.slider_width) / self.slider_x_max,
            color=GREY,
            numbers_with_elongated_ticks=numbers,
            tick_frequency=0.25,
        )
        line.add_numbers(*numbers)
        line.numbers.next_to(line, UP, buff=SMALL_BUFF)
        for number in line.numbers:
            number.add_background_rectangle()
        line.move_to(self.slider_center)

        triangle = RegularPolygon(
            3,
            start_angle=np.pi / 2,
            fill_color=self.slider_handle_color,
            fill_opacity=0.8,
            stroke_width=0,
        )
        triangle.scale_to_fit_height(self.x_slider_handle_height)
        triangle.move_to(line.number_to_point(x), UP)

        x_mob = TexMobject("x")
        x_mob.next_to(triangle, DOWN, buff=SMALL_BUFF)

        result = VGroup(line, triangle, x_mob)
        result.x_val = x
        return result
Exemplo n.º 4
0
 def get_graph_label(
     self, 
     graph, 
     label = "f(x)", 
     x_val = None,
     direction = RIGHT,
     buff = MED_SMALL_BUFF,
     color = None,
     ):
     label = TexMobject(label)
     color = color or graph.get_color()
     label.highlight(color)
     if x_val is None:
         #Search from right to left
         for x in np.linspace(self.x_max, self.x_min, 100):
             point = self.input_to_graph_point(x, graph)
             if point[1] < SPACE_HEIGHT:
                 break
         x_val = x
     label.next_to(
         self.input_to_graph_point(x_val, graph),
         direction,
         buff = buff
     )
     label.shift_onto_screen()
     return label
Exemplo n.º 5
0
    def add_point(self):
        point = self.plane.coords_to_point(3, 2)
        dot = Dot(point, color=self.dot_color)
        line = Line(self.plane.get_center_point(), point)
        line.highlight(dot.get_color())
        number_label = TexMobject("3+2i")
        number_label.add_background_rectangle()
        number_label.next_to(dot, RIGHT, SMALL_BUFF)
        distance_labels = VGroup()
        for tex in "3^2 + 2^2", "13":
            pre_label = TexMobject("\\sqrt{%s}" % tex)
            label = VGroup(
                BackgroundRectangle(pre_label),
                VGroup(*pre_label[:2]),
                VGroup(*pre_label[2:]),
            )
            label.scale(0.75)
            label.next_to(line.get_center(), UP, SMALL_BUFF)
            label.rotate(line.get_angle(), about_point=line.get_center())
            distance_labels.add(label)

        self.play(FadeIn(number_label), ShowCreation(line),
                  DrawBorderThenFill(dot))
        self.play(Write(distance_labels[0]))
        self.dither()
        self.play(ReplacementTransform(*distance_labels))
        self.dither()

        self.distance_label = distance_labels[1]
        self.line = line
        self.dot = dot
        self.number_label = number_label
Exemplo n.º 6
0
    def construct(self):
        cycloid = Cycloid()
        index = cycloid.get_num_points()/3
        point = cycloid.points[index]
        vect = cycloid.points[index+1]-point
        vect /= np.linalg.norm(vect)
        vect *= 3
        vect_mob = Vector(point, vect)
        dot = Dot(point)
        xy = TexMobject("\\big( x(t), y(t) \\big)")
        xy.next_to(dot, UP+RIGHT, buff = 0.1)
        vert_line = Line(2*DOWN, 2*UP)
        vert_line.shift(point)
        angle = vect_mob.get_angle() + np.pi/2
        arc = Arc(angle, radius = 1, start_angle = -np.pi/2)
        arc.shift(point)
        theta = TexMobject("\\theta(t)")
        theta.next_to(arc, DOWN, buff = 0.1, aligned_edge = LEFT)
        theta.shift(0.2*RIGHT)

        self.play(ShowCreation(cycloid))
        self.play(ShowCreation(dot))
        self.play(ShimmerIn(xy))
        self.dither()
        self.play(
            FadeOut(xy),
            ShowCreation(vect_mob)
        )
        self.play(
            ShowCreation(arc),
            ShowCreation(vert_line),
            ShimmerIn(theta)
        )
        self.dither()
Exemplo n.º 7
0
    def put_it_first(self):
        poker_example = self.get_poker_example()
        music_example = self.get_music_example()
        disease_group = self.disease_group

        self.play(disease_group.restore, disease_group.to_edge, LEFT,
                  RemovePiCreatureBubble(self.teacher, target_mode="hesitant"))
        self.change_student_modes(*["pondering"] * 3,
                                  look_at_arg=disease_group)

        poker_example.next_to(self.example, RIGHT)
        music_example.next_to(poker_example, RIGHT)
        examples = VGroup(poker_example, music_example)
        brace = Brace(examples, UP)
        bayes_to_intuition = VGroup(
            *map(TextMobject, ["Bayes", "$\\leftrightarrow$", "Intuition"]))
        bayes_to_intuition.arrange_submobjects(RIGHT, buff=SMALL_BUFF)
        bayes_to_intuition.next_to(brace, UP, SMALL_BUFF)
        check = TexMobject("\\checkmark")
        check.highlight(GREEN)
        check.next_to(bayes_to_intuition[1], UP, SMALL_BUFF)

        for example in examples:
            self.play(FadeIn(example))
            self.dither()
        self.play(GrowFromCenter(brace))
        self.play(FadeIn(bayes_to_intuition))
        self.play(Write(check))
        self.dither(2)

        self.intuitive_examples = VGroup(examples, brace, bayes_to_intuition,
                                         check)
Exemplo n.º 8
0
    def show_d_sine(self):
        ss_group = self.get_secant_slope_group(self.example_input,
                                               self.sine_graph,
                                               dx=self.dx,
                                               dx_label="dx",
                                               df_label="\\cos(0.5)dx",
                                               include_secant_line=False)
        for mob, vect in (ss_group.dx_label, UP), (ss_group.df_label, LEFT):
            mob.scale(4, about_point=mob.get_edge_center(vect))

        d_sine = self.deriv[2]
        brace = Brace(d_sine)
        cosine_dx = TexMobject("\\cos(x)", "dx")
        cosine_dx.scale(self.tex_scale_factor)
        cosine_dx.next_to(brace, DOWN)
        cosine_dx.highlight(d_sine.get_color())

        self.play(GrowFromCenter(brace), Write(cosine_dx))
        self.dither()
        self.play(
            self.little_rectangle.move_to,
            ss_group,
        )
        self.dither()
        self.play(Write(ss_group))
        self.dither()

        self.cosine = cosine_dx[0]
        self.sine_ss_group = ss_group
Exemplo n.º 9
0
    def complete_derivative(self):
        cosine = self.cosine.copy()
        two_x = self.two_x.copy()
        lhs = VGroup(*self.deriv_q[:3])
        to_fade = VGroup(*self.deriv_q[3:])
        for mob in cosine, two_x, lhs:
            mob.generate_target()
        lhs.target.next_to(self.func_mob, DOWN, aligned_edge=LEFT)
        cosine.target.next_to(lhs.target)
        plus = TexMobject("+").scale(self.tex_scale_factor)
        plus.next_to(cosine.target)
        two_x.target.next_to(plus)

        box = Rectangle(color=YELLOW)
        box.replace(VGroup(lhs.target, two_x.target), stretch=True)
        box.scale_in_place(1.2)

        self.play(FocusOn(self.deriv_q))
        self.play(Write(plus),
                  FadeOut(to_fade, rate_func=squish_rate_func(smooth, 0, 0.5)),
                  *map(MoveToTarget, [cosine, two_x, lhs]),
                  run_time=2)
        to_fade.highlight(BLACK)
        self.play(ShowCreation(box))
        self.dither(2)
Exemplo n.º 10
0
    def get_label_group(self, t):
        graph = self.graph

        v_line = self.get_vertical_line_to_graph(
            t,
            graph,
            color=YELLOW,
        )
        brace = Brace(v_line, RIGHT)
        height_label = brace.get_text("$2^%d$" % t)

        ss_group = self.get_secant_slope_group(
            t,
            graph,
            dx=0.01,
            df_label="dM",
            dx_label="dt",
            dx_line_color=GREEN,
            secant_line_color=RED,
        )
        slope_label = TexMobject("\\text{Slope}", "=", "2^%d" % t,
                                 "(%.7f\\dots)" % np.log(2))
        slope_label.next_to(ss_group.secant_line.point_from_proportion(0.65),
                            DOWN + RIGHT,
                            buff=0)
        slope_label.highlight_by_tex("Slope", RED)
        return VGroup(v_line, brace, height_label, ss_group, slope_label)
Exemplo n.º 11
0
    def construct(self):
        t_axis = NumberLine()
        theta_axis = NumberLine().rotate(np.pi / 2)
        theta_mob = TexMobject("\\theta(t)")
        t_mob = TexMobject("t")
        theta_mob.next_to(theta_axis, RIGHT)
        theta_mob.to_edge(UP)
        t_mob.next_to(t_axis, UP)
        t_mob.to_edge(RIGHT)
        graph = ParametricFunction(
            lambda t: 4 * t * RIGHT + 2 * smooth(t) * UP)
        line = Line(graph.points[0], graph.points[-1], color=WHITE)
        q_mark = TextMobject("?")
        q_mark.next_to(Point(graph.get_center()), LEFT)
        stars = Stars(color=BLACK)
        stars.scale(0.1).shift(q_mark.get_center())

        squiggle = ParametricFunction(lambda t: t * RIGHT + 0.2 * t * (5 - t) *
                                      (np.sin(t)**2) * UP,
                                      start=0,
                                      end=5)

        self.play(ShowCreation(t_axis), ShowCreation(theta_axis),
                  ShimmerIn(theta_mob), ShimmerIn(t_mob))
        self.play(ShimmerIn(q_mark), ShowCreation(graph))
        self.wait()
        self.play(Transform(q_mark, stars), Transform(graph, line))
        self.wait()
        self.play(Transform(graph, squiggle))
        self.wait()
Exemplo n.º 12
0
    def get_subdivision_braces_and_labels(
        self, parts, labels, direction,
        buff = SMALL_BUFF,
        min_num_quads = 1
        ):
        label_mobs = VGroup()
        braces = VGroup()
        for label, part in zip(labels, parts):
            brace = Brace(
                part, direction, 
                min_num_quads = min_num_quads, 
                buff = buff
            )
            if isinstance(label, Mobject):
                label_mob = label
            else:
                label_mob = TexMobject(label)
                label_mob.scale(self.default_label_scale_val)
            label_mob.next_to(brace, direction, buff)

            braces.add(brace)
            label_mobs.add(label_mob)
        parts.braces = braces
        parts.labels = label_mobs
        parts.label_kwargs = {
            "labels" : label_mobs.copy(),
            "direction" : direction, 
            "buff" : buff,
        }
        return VGroup(parts.braces, parts.labels)
Exemplo n.º 13
0
    def get_matrices(self):       
        m1_mob = Matrix(np.array(self.t_matrix1).transpose())
        m2_mob = Matrix(np.array(self.t_matrix2).transpose())
        comp_matrix = Matrix([["?", "?"], ["?", "?"]])        
        m1_mob.highlight(YELLOW)
        m2_mob.highlight(PINK)
        comp_matrix.get_entries().submobject_gradient_highlight(YELLOW, PINK)

        equals = TexMobject("=")
        equals.next_to(comp_matrix, LEFT)
        comp_matrix.add(equals)
        m1_mob = VMobject(BackgroundRectangle(m1_mob), m1_mob)
        m2_mob = VMobject(BackgroundRectangle(m2_mob), m2_mob)
        comp_matrix = VMobject(BackgroundRectangle(comp_matrix), comp_matrix)
        VMobject(
            m2_mob, m1_mob, comp_matrix
        ).arrange_submobjects(buff = 0.1).to_corner(UP+LEFT).shift(DOWN)

        for i, mob in enumerate([m1_mob, m2_mob]):
            brace = Brace(mob, UP)
            text = TexMobject("M_%d"%(i+1))
            text.next_to(brace, UP)
            brace.add_background_rectangle()
            text.add_background_rectangle()
            brace.add(text)
            mob.label = brace
        return m1_mob, m2_mob, comp_matrix
Exemplo n.º 14
0
    def show_proportionality_to_dx_squared(self):
        ddf = self.ddf.copy()
        ddf.generate_target()
        ddf.target.next_to(self.ddf, UP, LARGE_BUFF)
        rhs = TexMobject(
            "\\approx", "(\\text{Some constant})", "(dx)^2"
        )
        rhs.scale(0.8)
        rhs.next_to(ddf.target, RIGHT)

        example_dx = TexMobject(
            "dx = 0.01 \\Rightarrow (dx)^2 = 0.0001"
        )
        example_dx.scale(0.8)
        example_dx.to_corner(UP+RIGHT)

        self.play(MoveToTarget(ddf))
        self.play(Write(rhs))
        self.dither()
        self.play(Write(example_dx))
        self.dither(2)
        self.play(FadeOut(example_dx))

        self.ddf = ddf
        self.dx_squared = rhs.get_part_by_tex("dx")
Exemplo n.º 15
0
    def get_subdivision_braces_and_labels(
        self, parts, labels, direction,
        buff = SMALL_BUFF,
        min_num_quads = 1
        ):
        label_mobs = VGroup()
        braces = VGroup()
        for label, part in zip(labels, parts):
            brace = Brace(
                part, direction, 
                min_num_quads = min_num_quads, 
                buff = buff
            )
            if isinstance(label, Mobject):
                label_mob = label
            else:
                label_mob = TexMobject(label)
                label_mob.scale(self.default_label_scale_val)
            label_mob.next_to(brace, direction, buff)

            braces.add(brace)
            label_mobs.add(label_mob)
        parts.braces = braces
        parts.labels = label_mobs
        parts.label_kwargs = {
            "labels" : label_mobs.copy(),
            "direction" : direction, 
            "buff" : buff,
        }
        return VGroup(parts.braces, parts.labels)
Exemplo n.º 16
0
    def add_axes(self):
        x_axis = Line(self.tick_width*LEFT/2, self.width*RIGHT)
        y_axis = Line(MED_LARGE_BUFF*DOWN, self.height*UP)
        ticks = VGroup()
        heights = np.linspace(0, self.height, self.n_ticks+1)
        values = np.linspace(0, self.max_value, self.n_ticks+1)
        for y, value in zip(heights, values):
            tick = Line(LEFT, RIGHT)
            tick.scale_to_fit_width(self.tick_width)
            tick.move_to(y*UP)
            ticks.add(tick)
        y_axis.add(ticks)

        self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = x_axis, y_axis

        if self.label_y_axis:
            labels = VGroup()
            for tick, value in zip(ticks, values):
                label = TexMobject(str(np.round(value, 2)))
                label.scale_to_fit_height(self.y_axis_label_height)
                label.next_to(tick, LEFT, SMALL_BUFF)
                labels.add(label)
            self.y_axis_labels = labels
            self.add(labels)
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
    def get_label_group(self, t):
        graph = self.graph

        v_line = self.get_vertical_line_to_graph(
            t, graph,
            color = YELLOW,
        )
        brace = Brace(v_line, RIGHT)
        height_label = brace.get_text("$2^%d$"%t)

        ss_group = self.get_secant_slope_group(
            t, graph, dx = 0.01,
            df_label = "dM",
            dx_label = "dt",
            dx_line_color = GREEN,
            secant_line_color = RED,
        )
        slope_label = TexMobject(
            "\\text{Slope}", "=", 
            "2^%d"%t,
            "(%.7f\\dots)"%np.log(2)
        )
        slope_label.next_to(
            ss_group.secant_line.point_from_proportion(0.65),
            DOWN+RIGHT,
            buff = 0
        )
        slope_label.highlight_by_tex("Slope", RED)
        return VGroup(
            v_line, brace, height_label,
            ss_group, slope_label
        )
Exemplo n.º 19
0
    def get_matrices(self):
        m1_mob = Matrix(np.array(self.t_matrix1).transpose())
        m2_mob = Matrix(np.array(self.t_matrix2).transpose())
        comp_matrix = Matrix([["?", "?"], ["?", "?"]])
        m1_mob.highlight(YELLOW)
        m2_mob.highlight(PINK)
        comp_matrix.get_entries().submobject_gradient_highlight(YELLOW, PINK)

        equals = TexMobject("=")
        equals.next_to(comp_matrix, LEFT)
        comp_matrix.add(equals)
        m1_mob = VMobject(BackgroundRectangle(m1_mob), m1_mob)
        m2_mob = VMobject(BackgroundRectangle(m2_mob), m2_mob)
        comp_matrix = VMobject(BackgroundRectangle(comp_matrix), comp_matrix)
        VMobject(m2_mob, m1_mob, comp_matrix).arrange_submobjects(
            buff=0.1).to_corner(UP + LEFT).shift(DOWN)

        for i, mob in enumerate([m1_mob, m2_mob]):
            brace = Brace(mob, UP)
            text = TexMobject("M_%d" % (i + 1))
            text.next_to(brace, UP)
            brace.add_background_rectangle()
            text.add_background_rectangle()
            brace.add(text)
            mob.label = brace
        return m1_mob, m2_mob, comp_matrix
Exemplo n.º 20
0
    def construct(self):
        eq1 = TexMobject(
            "\\text{secant}(\\theta) = \\frac{1}{\\text{cosine}(\\theta)}"
        )
        eq2 = TexMobject(
            "\\text{cosecant}(\\theta) = \\frac{1}{\\text{sine}(\\theta)}"
        )
        eq1.to_corner(UP+LEFT)
        eq1.to_edge(LEFT)
        eq2.next_to(eq1, DOWN, buff = LARGE_BUFF)
        eqs = VGroup(eq1, eq2)

        self.play(
            self.get_teacher().change_mode, "speaking",
            Write(eqs),
            *[
                ApplyMethod(pi.look_at, eqs)
                for pi in self.get_students()
            ]
        )
        self.random_blink()
        self.play(
            VGroup(*eq1[-9:-7]).highlight, YELLOW,
            VGroup(*eq2[:2]).highlight, YELLOW,
            *[
                ApplyMethod(pi.change_mode, "confused")
                for pi in self.get_students()
            ]
        )
        self.random_blink(2)
Exemplo n.º 21
0
    def construct(self):
        v_color = MAROON_C
        w_color = BLUE
        words = TextMobject([
            "``Linear combination'' of", "$\\vec{\\textbf{v}}$", "and",
            "$\\vec{\\textbf{w}}$"
        ])
        words.split()[1].highlight(v_color)
        words.split()[3].highlight(w_color)
        words.scale_to_fit_width(2 * SPACE_WIDTH - 1)
        words.to_edge(UP)

        equation = TexMobject(
            ["a", "\\vec{\\textbf{v}}", "+", "b", "\\vec{\\textbf{w}}"])
        equation.arrange_submobjects(buff=0.1, aligned_edge=DOWN)
        equation.split()[1].highlight(v_color)
        equation.split()[4].highlight(w_color)
        a, b = np.array(equation.split())[[0, 3]]
        equation.scale(2)
        equation.next_to(words, DOWN, buff=1)

        scalars_word = TextMobject("Scalars")
        scalars_word.scale(1.5)
        scalars_word.next_to(equation, DOWN, buff=2)
        arrows = [Arrow(scalars_word, letter) for letter in a, b]

        self.add(equation)
        self.play(Write(words))
        self.play(ShowCreation(VMobject(*arrows)), Write(scalars_word))
        self.wait(2)
Exemplo n.º 22
0
    def add_conditional_divisions(self):
        sample_space = self.sample_space
        top_part, bottom_part = sample_space.horizontal_parts

        top_brace = Brace(top_part, UP)
        top_label = TexMobject("P(", "+", "|", "\\text{Disease}", ")", "=",
                               "1")
        top_label.scale(0.7)
        top_label.next_to(top_brace, UP)
        top_label.highlight_by_tex("+", GREEN)

        self.play(GrowFromCenter(top_brace))
        self.play(FadeIn(top_label))
        self.dither()

        bottom_part.divide_vertically(0.95, colors=[BLUE_E, YELLOW_E])
        bottom_label = TexMobject("P(", "+", "|", "\\text{Not disease}", ")",
                                  "=", "1")
        bottom_label.scale(0.7)
        bottom_label.highlight_by_tex("+", GREEN)
        braces, labels = bottom_part.get_bottom_braces_and_labels(
            [bottom_label])
        bottom_brace = braces[0]

        self.play(
            FadeIn(bottom_part.vertical_parts),
            GrowFromCenter(bottom_brace),
        )
        self.play(FadeIn(bottom_label))
        self.dither()
Exemplo n.º 23
0
    def add_scaling(self, arrows, syms, arrays):
        s_arrows = VMobject(
            TexMobject("2"), Vector([1, 1]).highlight(YELLOW), 
            TexMobject("="), Vector([2, 2]).highlight(WHITE)
        )
        s_arrows.arrange_submobjects(RIGHT)
        s_arrows.scale(0.75)
        s_arrows.next_to(arrows, DOWN)

        s_arrays = VMobject(
            TexMobject("2"), 
            matrix_to_mobject([3, -5]).highlight(YELLOW),
            TextMobject("="),
            matrix_to_mobject(["2(3)", "2(-5)"])
        )
        s_arrays.arrange_submobjects(RIGHT)
        s_arrays.scale(0.75)
        s_arrays.next_to(arrays, DOWN)

        s_syms = TexMobject(["2", "\\vec{\\textbf{v}}"])
        s_syms.split()[-1].highlight(YELLOW)
        s_syms.next_to(syms, DOWN)

        self.play(
            Write(s_arrows), Write(s_arrays), Write(s_syms),
            run_time = 2
        )
        self.wait()
Exemplo n.º 24
0
    def construct(self):
        point_a, point_b = 3*LEFT, 3*RIGHT
        dots = []
        for point, char in [(point_a, "A"), (point_b, "B")]:
            dot = Dot(point)
            letter = TexMobject(char)
            letter.next_to(dot, UP+LEFT)
            dot.add(letter)
            dots.append(dot)

        path = ParametricFunction(
            lambda t : (t/2 + np.cos(t))*RIGHT + np.sin(t)*UP,
            start = -2*np.pi,
            end = 2*np.pi
        )
        path.scale(6/(2*np.pi))
        path.shift(point_a - path.points[0])
        path.highlight(RED)
        line = Line(point_a, point_b)
        words = TextMobject("Shortest path from $A$ to $B$")
        words.to_edge(UP)

        self.play(
            ShimmerIn(words),
            *map(GrowFromCenter, dots)
        )
        self.play(ShowCreation(path))
        self.play(Transform(
            path, line,
            path_func = path_along_arc(np.pi)
        ))
        self.dither()
Exemplo n.º 25
0
    def various_arc_sizes_for_p1_p2_placements(self):
        arc = self.arc

        self.triangle.save_state()
        self.play(*map(FadeOut, [
            self.push_pins, self.triangle, self.arc_lines
        ]))
        self.update_animations.remove(self.triangle_update)
        self.update_animations += [
            self.get_center_lines_update(self.point_mobs, self.center_lines),
            self.get_arcs_update(self.all_arcs)
        ]

        #90 degree angle
        self.change_point_mobs_to_angles([np.pi/2, np.pi], run_time = 1)
        elbow = VGroup(
            Line(DOWN, DOWN+RIGHT),
            Line(DOWN+RIGHT, RIGHT),
        )
        elbow.scale(0.25)
        elbow.shift(self.center)
        ninety_degrees = TexMobject("90^\\circ")
        ninety_degrees.next_to(elbow, DOWN+RIGHT, buff = 0)
        proportion = DecimalNumber(0.25)
        proportion.highlight(self.center_color)
        # proportion.next_to(arc.point_from_proportion(0.5), DOWN, MED_LARGE_BUFF)
        proportion.next_to(self.arc_size_arrow, DOWN)
        def proportion_update_func(alpha):
            angles = self.get_point_mob_angles()
            diff = abs(angles[1]-angles[0])/(2*np.pi)
            return min(diff, 1-diff)
        proportion_update = ChangingDecimal(proportion, proportion_update_func)

        self.play(ShowCreation(elbow), FadeIn(ninety_degrees))
        self.dither()
        self.play(
            ApplyMethod(
                arc.rotate_in_place, np.pi/12,
                rate_func = wiggle,
            )
        )
        self.play(LaggedStart(FadeIn, proportion, run_time = 1))
        self.dither()

        #Non right angles
        angle_pairs = [
            (0.26*np.pi, 1.24*np.pi), 
            (0.73*np.pi, 0.78*np.pi),
            (0.5*np.pi, np.pi),
        ]
        self.update_animations.append(proportion_update)
        for angle_pair in angle_pairs:
            self.change_point_mobs_to_angles(
                angle_pair,
                VGroup(elbow, ninety_degrees).fade, 1,
            )
            self.remove(elbow, ninety_degrees)
            self.dither()

        self.set_variables_as_attrs(proportion, proportion_update)
Exemplo n.º 26
0
    def construct(self):
        p_tex = "$%s$"%get_vect_tex("p")
        p_mob = TextMobject(p_tex)
        p_mob.scale(1.5)
        p_mob.highlight(P_COLOR)
        input_array = Matrix(list("xyz"))
        dot_product = Group(p_mob, Dot(radius = 0.07), input_array)
        dot_product.arrange_submobjects(buff = MED_BUFF/2)
        equals = TexMobject("=")
        dot_product.next_to(equals, LEFT)
        words = Group(*it.starmap(TextMobject, [
            ("(Length of projection)",),
            ("(Length of ", p_tex, ")",)
        ]))
        times = TexMobject("\\times")
        words[1].highlight_by_tex(p_tex, P_COLOR)
        words[0].next_to(equals, RIGHT)
        words[1].next_to(words[0], DOWN, aligned_edge = LEFT)
        times.next_to(words[0], RIGHT)

        everyone = Group(dot_product, equals, times, words)
        everyone.center().scale_to_fit_width(SPACE_WIDTH - 1)
        self.add(dot_product)
        self.play(Write(equals))
        self.play(Write(words[0]))
        self.dither()
        self.play(
            Write(times),
            Write(words[1])
        )
        self.dither()
Exemplo n.º 27
0
    def show_d_x_squared(self):
        ss_group = self.get_secant_slope_group(self.example_input,
                                               self.parabola,
                                               dx=self.dx,
                                               dx_label="dx",
                                               df_label="2(0.5)dx",
                                               include_secant_line=False)
        for mob, vect in (ss_group.dx_label, UP), (ss_group.df_label, LEFT):
            mob.scale(3, about_point=mob.get_edge_center(vect))

        d_x_squraed = self.deriv[4]
        brace = Brace(d_x_squraed)
        two_x_dx = TexMobject("2x", "\\,dx")
        two_x_dx.scale(self.tex_scale_factor)
        two_x_dx.next_to(brace, DOWN)
        two_x_dx.highlight(d_x_squraed.get_color())

        self.play(FocusOn(two_x_dx))
        self.play(GrowFromCenter(brace), Write(two_x_dx))
        self.dither()
        self.play(
            self.little_rectangle.move_to,
            ss_group,
        )
        self.dither()
        self.play(Write(ss_group))
        self.dither()

        self.two_x = two_x_dx[0]
        self.x_squared_ss_group = ss_group
Exemplo n.º 28
0
    def specifics_concepts(self):
        matrix_vector_product = TexMobject(" ".join([
            matrix_to_tex_string(EXAMPLE_TRANFORM),
            matrix_to_tex_string(TRANFORMED_VECTOR),
            "&=",
            matrix_to_tex_string([
                ["1 \\cdot 1 + 0 \\cdot 2"], 
                ["1 \\cdot 1 + (-1)\\cdot 2"]
            ]),
            "\\\\ &=",
            matrix_to_tex_string([[1], [-1]]),
        ]))
        matrix_vector_product.scale_to_fit_width(SPACE_WIDTH-0.5)
        matrix_vector_product.next_to(self.vline, LEFT)

        self.play(
            Write(self.numeric),
            FadeIn(matrix_vector_product),
            run_time = 2
        )
        self.dither()
        self.play(Write(self.geometric, run_time = 2))
        ### Paste in linear transformation
        self.dither()
        digest_locals(self)
Exemplo n.º 29
0
 def get_graph_label(
     self, 
     graph, 
     label = "f(x)", 
     x_val = None,
     direction = RIGHT,
     buff = MED_SMALL_BUFF,
     color = None,
     ):
     label = TexMobject(label)
     color = color or graph.get_color()
     label.highlight(color)
     if x_val is None:
         #Search from right to left
         for x in np.linspace(self.x_max, self.x_min, 100):
             point = self.input_to_graph_point(x, graph)
             if point[1] < SPACE_HEIGHT:
                 break
         x_val = x
     label.next_to(
         self.input_to_graph_point(x_val, graph),
         direction,
         buff = buff
     )
     label.shift_onto_screen()
     return label
Exemplo n.º 30
0
    def construct(self):
        title = TextMobject("Function composition")
        title.to_edge(UP)

        sine = TexMobject("g(", "x", ")", "=", "\\sin(", "x", ")")
        sine.highlight(SINE_COLOR)
        x_squared = TexMobject("h(x)", "=", "x^2")
        x_squared.highlight(X_SQUARED_COLOR)
        group = VGroup(sine, x_squared)
        group.arrange_submobjects(buff=LARGE_BUFF)
        group.shift(UP)
        composition = TexMobject("g(", "h(x)", ")", "=", "\\sin(", "x^2", ")")
        for i in 0, 2, 4, 6:
            composition[i].highlight(SINE_COLOR)
        for i in 1, 5:
            composition[i].highlight(X_SQUARED_COLOR)
        composition.next_to(group, DOWN, buff=LARGE_BUFF)

        brace = Brace(VGroup(*composition[-3:]), DOWN)
        deriv_q = brace.get_text("Derivative?")

        self.add(group)
        self.play(Write(title))
        self.dither()
        triplets = [[sine, (0, 2), (0, 2)], [x_squared, (0, ), (1, )],
                    [sine, (3, 4, 6), (3, 4, 6)], [x_squared, (2, ), (5, )]]
        for premob, pre_indices, comp_indicies in triplets:
            self.play(*[
                ReplacementTransform(premob[i].copy(), composition[j])
                for i, j in zip(pre_indices, comp_indicies)
            ])
            self.dither()
        self.dither()
        self.play(GrowFromCenter(brace), Write(deriv_q))
        self.dither()
Exemplo n.º 31
0
    def construct(self):
        two_dot = TexMobject("2\\cdot")
        equals = TexMobject("=")
        self.add_axes()
        v = self.add_vector([3, 1])
        v_coords, vx_line, vy_line = self.vector_to_coords(v, clean_up=False)
        self.play(ApplyMethod(v_coords.to_edge, UP))
        two_dot.next_to(v_coords, LEFT)
        equals.next_to(v_coords, RIGHT)
        two_v = self.add_vector([6, 2], animate=False)
        self.remove(two_v)
        self.play(Transform(v.copy(), two_v), Write(two_dot, run_time=1))
        two_v_coords, two_v_x_line, two_v_y_line = self.vector_to_coords(
            two_v, clean_up=False)
        self.play(ApplyMethod(two_v_coords.next_to, equals, RIGHT),
                  Write(equals, run_time=1))
        self.dither(2)

        x, y = v_coords.get_mob_matrix().flatten()
        two_v_elems = two_v_coords.get_mob_matrix().flatten()
        x_sym, y_sym = map(TexMobject, ["x", "y"])
        two_x_sym, two_y_sym = map(TexMobject, ["2x", "2y"])
        VMobject(x_sym, two_x_sym).highlight(X_COLOR)
        VMobject(y_sym, two_y_sym).highlight(Y_COLOR)
        syms = [x_sym, y_sym, two_x_sym, two_y_sym]
        VMobject(*syms).scale(VECTOR_LABEL_SCALE_FACTOR)
        for sym, num in zip(syms, [x, y] + list(two_v_elems)):
            sym.move_to(num)
        self.play(Transform(x, x_sym), Transform(y, y_sym),
                  FadeOut(VMobject(*two_v_elems)))
        self.dither()
        self.play(Transform(VMobject(two_dot.copy(), x.copy()), two_x_sym),
                  Transform(VMobject(two_dot.copy(), y.copy()), two_y_sym))
        self.dither(2)
Exemplo n.º 32
0
    def add_scaling(self, arrows, syms, arrays):
        s_arrows = VMobject(
            TexMobject("2"), Vector([1, 1]).highlight(YELLOW), 
            TexMobject("="), Vector([2, 2]).highlight(WHITE)
        )
        s_arrows.arrange_submobjects(RIGHT)
        s_arrows.scale(0.75)
        s_arrows.next_to(arrows, DOWN)

        s_arrays = VMobject(
            TexMobject("2"), 
            matrix_to_mobject([3, -5]).highlight(YELLOW),
            TextMobject("="),
            matrix_to_mobject(["2(3)", "2(-5)"])
        )
        s_arrays.arrange_submobjects(RIGHT)
        s_arrays.scale(0.5)
        s_arrays.next_to(arrays, DOWN)

        s_syms = TexMobject(["2", "\\vec{\\textbf{v}}"])
        s_syms.split()[-1].highlight(YELLOW)
        s_syms.next_to(syms, DOWN)

        self.play(
            Write(s_arrows), Write(s_arrays), Write(s_syms),
            run_time = 2
        )
        self.dither()
Exemplo n.º 33
0
    def construct(self):
        p_tex = "$%s$" % get_vect_tex("p")
        p_mob = TextMobject(p_tex)
        p_mob.scale(1.5)
        p_mob.highlight(P_COLOR)
        input_array = Matrix(list("xyz"))
        dot_product = VGroup(p_mob, Dot(radius=0.07), input_array)
        dot_product.arrange_submobjects(buff=MED_SMALL_BUFF / 2)
        equals = TexMobject("=")
        dot_product.next_to(equals, LEFT)
        words = VGroup(*it.starmap(TextMobject, [(
            "(Length of projection)", ), (
                "(Length of ",
                p_tex,
                ")",
            )]))
        times = TexMobject("\\times")
        words[1].highlight_by_tex(p_tex, P_COLOR)
        words[0].next_to(equals, RIGHT)
        words[1].next_to(words[0], DOWN, aligned_edge=LEFT)
        times.next_to(words[0], RIGHT)

        everyone = VGroup(dot_product, equals, times, words)
        everyone.center().scale_to_fit_width(SPACE_WIDTH - 1)
        self.add(dot_product)
        self.play(Write(equals))
        self.play(Write(words[0]))
        self.dither()
        self.play(Write(times), Write(words[1]))
        self.dither()
Exemplo n.º 34
0
    def construct(self):
        signature = get_cursive_name("Alice")
        signature.scale(1.5)
        signature.highlight(BLUE_C)
        signature.to_corner(UP + LEFT)
        signature_copy = signature.copy()
        signature_copy.shift(3 * RIGHT)

        bits = TexMobject("01100001")
        bits.next_to(signature, DOWN)
        bits.shift_onto_screen()
        bits_copy = bits.copy()
        bits_copy.next_to(signature_copy, DOWN)

        self.add(signature)

        self.student_says("Couldn't you just \\\\ copy the signature?",
                          target_mode="confused",
                          run_time=1)
        self.change_student_modes("pondering", "confused", "erm")
        self.play(LaggedStart(FadeIn, bits, run_time=1))
        self.dither()
        self.play(
            ReplacementTransform(bits.copy(), bits_copy, path_arc=np.pi / 2))
        self.play(Write(signature_copy))
        self.dither(3)
Exemplo n.º 35
0
    def construct(self):
        point_a, point_b = 3 * LEFT, 3 * RIGHT
        dots = []
        for point, char in [(point_a, "A"), (point_b, "B")]:
            dot = Dot(point)
            letter = TexMobject(char)
            letter.next_to(dot, UP + LEFT)
            dot.add(letter)
            dots.append(dot)

        path = ParametricFunction(lambda t:
                                  (t / 2 + np.cos(t)) * RIGHT + np.sin(t) * UP,
                                  start=-2 * np.pi,
                                  end=2 * np.pi)
        path.scale(6 / (2 * np.pi))
        path.shift(point_a - path.points[0])
        path.highlight(RED)
        line = Line(point_a, point_b)
        words = TextMobject("Shortest path from $A$ to $B$")
        words.to_edge(UP)

        self.play(ShimmerIn(words), *map(GrowFromCenter, dots))
        self.play(ShowCreation(path))
        self.play(Transform(path, line, path_func=path_along_arc(np.pi)))
        self.wait()
Exemplo n.º 36
0
    def construct(self):
        lhs = TexMobject(["\\text{det}(", "M_1", "M_2", ")"])
        det, m1, m2, rp = lhs.split()
        m1.highlight(TEAL)
        m2.highlight(PINK)

        rhs = TexMobject(["=\\text{det}(", "M_1", ")\\text{det}(", "M_2", ")"])
        rhs.split()[1].highlight(TEAL)
        rhs.split()[3].highlight(PINK)

        rhs.next_to(lhs, RIGHT)
        formula = VMobject(lhs, rhs)
        formula.center()

        title = TextMobject("Explain in one sentence")
        title.highlight(YELLOW)
        title.next_to(formula, UP, buff=0.5)

        self.play(Write(m1))
        self.play(Write(m2))
        self.wait()
        self.play(Write(det), Write(rp))
        self.play(Write(rhs))
        self.wait(2)
        self.play(Write(title))
        self.wait(2)
Exemplo n.º 37
0
    def construct(self):
        underlying = TextMobject("Underlying \\\\ system")
        underlying.shift(DOWN).to_edge(LEFT)
        user_facing = TextMobject("User-facing")
        user_facing.next_to(underlying, UP, LARGE_BUFF, LEFT)

        protocol = TextMobject("Bitcoin protocol")
        protocol.next_to(underlying, RIGHT, MED_LARGE_BUFF)
        protocol.highlight(BITCOIN_COLOR)
        banking = TextMobject("Banking system")
        banking.next_to(protocol, RIGHT, MED_LARGE_BUFF)
        banking.highlight(GREEN)

        phone = SVGMobject(
            file_name="phone",
            fill_color=WHITE,
            fill_opacity=1,
            height=1,
            stroke_width=0,
        )
        phone.next_to(protocol, UP, LARGE_BUFF)
        card = SVGMobject(file_name="credit_card",
                          fill_color=LIGHT_GREY,
                          fill_opacity=1,
                          stroke_width=0,
                          height=1)
        card.next_to(banking, UP, LARGE_BUFF)

        btc = BitcoinLogo()
        btc.next_to(phone, UP, MED_LARGE_BUFF)
        dollar = TexMobject("\\$")
        dollar.scale_to_fit_height(1)
        dollar.highlight(GREEN)
        dollar.next_to(card, UP, MED_LARGE_BUFF)
        card.save_state()
        card.shift(2 * RIGHT)
        card.set_fill(opacity=0)

        h_line = Line(underlying.get_left(), banking.get_right())
        h_line.next_to(underlying, DOWN, MED_SMALL_BUFF, LEFT)
        h_line2 = h_line.copy()
        h_line2.next_to(user_facing, DOWN, MED_LARGE_BUFF, LEFT)
        h_line3 = h_line.copy()
        h_line3.next_to(user_facing, UP, MED_LARGE_BUFF, LEFT)
        v_line = Line(5 * UP, ORIGIN)
        v_line.next_to(underlying, RIGHT, MED_SMALL_BUFF)
        v_line.shift(1.7 * UP)
        v_line2 = v_line.copy()
        v_line2.next_to(protocol, RIGHT, MED_SMALL_BUFF)
        v_line2.shift(1.7 * UP)

        self.add(h_line, h_line2, h_line3, v_line, v_line2)
        self.add(underlying, user_facing, btc)
        self.play(Write(protocol))
        self.dither(2)
        self.play(card.restore, Write(dollar))
        self.play(Write(banking))
        self.dither(2)
        self.play(DrawBorderThenFill(phone))
        self.dither(2)
Exemplo n.º 38
0
    def show_diameter(self):
        exceptions = [
            self.circle, self.tangent_line, self.pc_line,
            self.right_angle_symbol
        ]
        everything = set(self.mobjects).difference(exceptions)
        everything_copy = Mobject(*everything).copy()
        light_everything = everything_copy.copy()
        dark_everything = everything_copy.copy()
        dark_everything.fade(0.8)
        bottom_point = np.array(self.c_point)
        bottom_point += 2 * self.radius * DOWN
        diameter = Line(bottom_point, self.c_point)
        brace = Brace(diameter, RIGHT)
        diameter_word = TextMobject("Diameter")
        d_mob = TexMobject("D")
        diameter_word.next_to(brace)
        d_mob.next_to(diameter)

        self.remove(*everything)
        self.play(Transform(everything_copy, dark_everything))
        self.dither()
        self.play(ShowCreation(diameter))
        self.play(GrowFromCenter(brace))
        self.play(ShimmerIn(diameter_word))
        self.dither()
        self.play(*[Transform(mob, d_mob) for mob in brace, diameter_word])
        self.remove(brace, diameter_word)
        self.add(d_mob)
        self.play(Transform(everything_copy, light_everything))
        self.remove(everything_copy)
        self.add(*everything)

        self.d_mob = d_mob
        self.bottom_point = bottom_point
Exemplo n.º 39
0
    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.wait()
        self.animate_secant_slope_group_change(
            ss_group, target_x = self.x2,
            run_time = 3
        )
        self.wait()

        self.ss_group = ss_group
        self.deriv = deriv
Exemplo n.º 40
0
    def show_proportionality_to_dx_squared(self):
        ddf = self.ddf.copy()
        ddf.generate_target()
        ddf.target.next_to(self.ddf, UP, LARGE_BUFF)
        rhs = TexMobject(
            "\\approx", "(\\text{Some constant})", "(dx)^2"
        )
        rhs.scale(0.8)
        rhs.next_to(ddf.target, RIGHT)

        example_dx = TexMobject(
            "dx = 0.01 \\Rightarrow (dx)^2 = 0.0001"
        )
        example_dx.scale(0.8)
        example_dx.to_corner(UP+RIGHT)

        self.play(MoveToTarget(ddf))
        self.play(Write(rhs))
        self.wait()
        self.play(Write(example_dx))
        self.wait(2)
        self.play(FadeOut(example_dx))

        self.ddf = ddf
        self.dx_squared = rhs.get_part_by_tex("dx")
Exemplo n.º 41
0
    def refocus_on_euler_sum(self):

        self.euler_sum.add(self.pi_answer)

        self.play(
            FadeOut(self.leibniz_sum), FadeOut(self.wallis_product),
            ApplyMethod(self.euler_sum.shift,
                        ORIGIN + 2 * UP - self.euler_sum.get_center()))

        # focus on pi squared
        pi_squared = self.euler_sum.get_part_by_tex("\\pi")[-3]
        self.play(ScaleInPlace(pi_squared, 2, rate_func=wiggle))

        # Morty thinks of a circle

        q_circle = Circle(stroke_color=YELLOW,
                          fill_color=YELLOW,
                          fill_opacity=0.5,
                          radius=0.4,
                          stroke_width=10.0)
        q_mark = TexMobject("?")
        q_mark.next_to(q_circle)

        thought = Group(q_circle, q_mark)
        q_mark.scale_to_fit_height(0.8 * q_circle.get_height())
        self.pi_creature_thinks(thought,
                                target_mode="confused",
                                bubble_kwargs={
                                    "height": 2,
                                    "width": 3
                                })

        self.wait()
Exemplo n.º 42
0
    def show_y(self):
        y_equals = TexMobject(["y", "="])
        y_equals.shift(2*UP)
        y_expression = TexMobject([
            "D ", "\\sin", "^2", "(\\theta)"
        ])
        y_expression.next_to(y_equals)
        y_expression.shift(0.05*UP+0.1*RIGHT)
        temp_expr = self.d_sin_squared_theta.copy()
        temp_expr.rotate(-np.pi/2)
        temp_expr.replace(y_expression)
        y_mob = TexMobject("y")
        y_mob.next_to(self.y_line, RIGHT)
        y_mob.shift(0.2*UP)

        self.play(
            Transform(self.d_sin_squared_theta, temp_expr),
            ShimmerIn(y_mob),
            ShowCreation(y_equals)
        )
        self.remove(self.d_sin_squared_theta)
        self.add(y_expression)

        self.y_equals = y_equals
        self.y_expression = y_expression
Exemplo n.º 43
0
    def show_geometry(self, slider, vector):
        point_a = self.point_a.get_center()
        horiz_line = Line(point_a, point_a + 6*RIGHT)
        ceil_point = point_a
        ceil_point[0] = slider.get_center()[0]
        vert_brace = Brace(
            Mobject(Point(ceil_point), Point(slider.get_center())),
            RIGHT,
            buff = 0.5
        )
        vect_brace = Brace(slider)
        vect_brace.stretch_to_fit_width(vector.get_length())
        vect_brace.rotate(np.arctan(vector.get_slope()))
        vect_brace.center().shift(vector.get_center())
        nudge = 0.2*(DOWN+LEFT)
        vect_brace.shift(nudge)
        y_mob = TexMobject("y")
        y_mob.next_to(vert_brace)
        sqrt_y = TexMobject("k\\sqrt{y}")
        sqrt_y.scale(0.5)
        sqrt_y.shift(vect_brace.get_center())
        sqrt_y.shift(3*nudge)

        self.play(ShowCreation(horiz_line))
        self.play(
            GrowFromCenter(vert_brace),
            ShimmerIn(y_mob)
        )
        self.play(
            GrowFromCenter(vect_brace),
            ShimmerIn(sqrt_y)
        )
        self.dither(3)
        self.solve_energy()
Exemplo n.º 44
0
    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.wait()
        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
Exemplo n.º 45
0
    def construct(self):
        series = VideoSeries()
        series.to_edge(UP)
        this_video = series[3]
        next_video = series[4]
        brace = Brace(this_video, DOWN)
        this_video.save_state()
        this_video.highlight(YELLOW)

        this_tex = TexMobject(
            "{d(", "a^t", ") \\over dt} = ", "a^t", "\\ln(a)"
        )
        this_tex[1][1].highlight(YELLOW)
        this_tex[3][1].highlight(YELLOW)
        this_tex.next_to(brace, DOWN)

        next_tex = VGroup(*map(TextMobject, [
            "Chain rule", "Product rule", "$\\vdots$"
        ]))
        next_tex.arrange_submobjects(DOWN)
        next_tex.next_to(brace, DOWN)
        next_tex.shift(
            next_video.get_center()[0]*RIGHT\
            -next_tex.get_center()[0]*RIGHT
        )

        self.add(series, brace, *this_tex[:3])
        self.change_student_modes(
            "confused", "pondering", "erm",
            look_at_arg = this_tex
        )
        self.play(ReplacementTransform(
            this_tex[1].copy(), this_tex[3]
        ))
        self.dither()
        self.play(
            Write(this_tex[4]),
            ReplacementTransform(
                this_tex[3][0].copy(),
                this_tex[4][3],
                path_arc = np.pi,
                remover = True
            )
        )
        self.dither(2)
        self.play(this_tex.replace, this_video)
        self.play(
            brace.next_to, next_video, DOWN,
            this_video.restore,
            Animation(this_tex),
            next_video.highlight, YELLOW,
            Write(next_tex),
            self.get_teacher().change_mode, "raise_right_hand"
        )
        self.change_student_modes(
            *["pondering"]*3,
            look_at_arg = next_tex
        )
        self.dither(3)
Exemplo n.º 46
0
 def construct(self):
     but = TextMobject("but")
     dots = TexMobject("\\dots")
     dots.next_to(but, aligned_edge = DOWN)
     but.shift(20*RIGHT)
     self.play(ApplyMethod(but.shift, 20*LEFT))
     self.play(Write(dots, run_time = 5))
     self.dither()
Exemplo n.º 47
0
 def get_axis_labels(self, x_label = "x", y_label = "y"):
     x_axis, y_axis = self.get_axes().split()
     x_label_mob = TexMobject(x_label)
     y_label_mob = TexMobject(y_label)
     x_label_mob.next_to(x_axis, DOWN)
     x_label_mob.to_edge(RIGHT)
     y_label_mob.next_to(y_axis, RIGHT)
     y_label_mob.to_edge(UP)
     return VMobject(x_label_mob, y_label_mob)
Exemplo n.º 48
0
 def get_kilogoogle(self):
     G = self.get_google_logo()[-1]
     kilo = TextMobject("K")
     kilo.scale(1.5)
     kilo.next_to(G[-1], LEFT, SMALL_BUFF, DOWN)
     plus_plus = TexMobject("++")
     plus_plus.set_stroke(width = 1)
     plus_plus.next_to(G, RIGHT, SMALL_BUFF)
     return VGroup(kilo, G, plus_plus)
Exemplo n.º 49
0
    def reset(self):
        time = self.t_expression[-1]
        faders = [time] + list(self.get_on_screen_pi_creatures())
        new_time = TexMobject("0")
        new_time.next_to(self.t_expression[-2], RIGHT)
        first_creature = self.get_pi_creatures()[0]

        self.play(*map(FadeOut, faders))
        self.play(*map(FadeIn, [first_creature, new_time]))
        self.t_expression.submobjects[-1] = new_time
Exemplo n.º 50
0
    def rearrange(self):
        sqrt_nudge = 0.2*LEFT        
        y, equals = self.y_equals.split()
        d, sin, squared, theta = self.y_expression.split()
        y_sqrt = TexMobject("\\sqrt{\\phantom{y}}")
        d_sqrt = y_sqrt.copy()
        y_sqrt.shift(y.get_center()+sqrt_nudge)
        d_sqrt.shift(d.get_center()+sqrt_nudge)

        self.play(
            ShimmerIn(y_sqrt),
            ShimmerIn(d_sqrt),
            ApplyMethod(squared.shift, 4*UP),
            ApplyMethod(theta.shift, 1.5* squared.get_width()*LEFT)
        )
        self.dither()
        y_sqrt.add(y)
        d_sqrt.add(d)
        sin.add(theta)

        sin_over = TexMobject("\\dfrac{\\phantom{\\sin(\\theta)}}{\\quad}")
        sin_over.next_to(sin, DOWN, 0.15)
        new_eq = equals.copy()
        new_eq.next_to(sin_over, LEFT)
        one_over = TexMobject("\\dfrac{1}{\\quad}")
        one_over.next_to(new_eq, LEFT)
        one_over.shift(
            (sin_over.get_bottom()[1]-one_over.get_bottom()[1])*UP
        )

        self.play(
            Transform(equals, new_eq),
            ShimmerIn(sin_over),
            ShimmerIn(one_over),
            ApplyMethod(
                d_sqrt.next_to, one_over, DOWN,
                path_func = path_along_arc(-np.pi)
            ),
            ApplyMethod(
                y_sqrt.next_to, sin_over, DOWN,
                path_func = path_along_arc(-np.pi)
            ),
            run_time = 2
        )
        self.dither()

        brace = Brace(d_sqrt, DOWN)
        constant = TextMobject("Constant")
        constant.next_to(brace, DOWN)

        self.play(
            GrowFromCenter(brace),
            ShimmerIn(constant)
        )
Exemplo n.º 51
0
    def shift_to_good_and_back(self):
        sum2 = self.sum1.copy()
        sigma = sum2.submobjects[1]
        plus = TexMobject("+").replace(sigma)
        sum2.submobjects[1] = plus

        prod2 = self.prod1.copy()
        pi = prod2.submobjects[0]
        times = TexMobject("\\times").replace(pi)
        prod2.submobjects[0] = times

        new_sin, new_cos, new_tan = [
            VMobject().set_anchor_points(
                corners, mode = "corners"
            ).replace(trig_part.split()[0])
            for corners, trig_part in zip(
                [
                    [RIGHT, RIGHT+UP, LEFT],
                    [RIGHT+UP, LEFT, RIGHT],
                    [RIGHT+UP, RIGHT, LEFT],
                ],
                self.trigs1.split()
            )
        ]
        x1, x2, x3 = [
            trig_part.split()[1]
            for trig_part in self.trigs1.split()
        ]
        trigs2 = VMobject(
            VMobject(new_sin, x1),
            VMobject(new_cos, x2),
            VMobject(new_tan, x3),
        )

        x, arrow, y = TexMobject("x \\rightarrow y").split()
        f = TexMobject("f")
        f.next_to(arrow, UP)
        func2 = VMobject(f, VMobject(), x, VMobject(), arrow, y)
        func2.scale(0.5)
        func2.shift(self.func1.get_center())

        good_symbols = VMobject(sum2, prod2, trigs2, func2)
        bad_symbols = self.symbols.copy()
        self.play(Transform(
            self.symbols, good_symbols, 
            path_arc = np.pi
        ))
        self.dither(3)
        self.play(Transform(
            self.symbols, bad_symbols,
            path_arc = np.pi
        ))
        self.dither()
Exemplo n.º 52
0
    def generate_points(self):
        index = int(self.cycloid_fraction*self.cycloid.get_num_points())
        p_point = self.cycloid.points[index]
        p_dot = Dot(p_point)
        p_label = TexMobject("P")
        p_label.next_to(p_dot, DOWN+LEFT)
        c_point = self.point_a + self.cycloid_fraction*self.radius*2*np.pi*RIGHT
        c_dot = Dot(c_point)
        c_label = TexMobject("C")
        c_label.next_to(c_dot, UP)

        digest_locals(self)
Exemplo n.º 53
0
    def isolate_bend_points(self):
        arc_radius = 0.1
        self.activate_zooming()
        little_square = self.get_zoomed_camera_mobject()

        for index in range(3):
            bend_point = self.bend_points[index]
            line = Line(
                bend_point+DOWN, 
                bend_point+UP,
                color = WHITE,
                density = self.zoom_factor*DEFAULT_POINT_DENSITY_1D
            )
            angle_arcs = []
            for i, rotation in [(index, np.pi/2), (index+1, -np.pi/2)]:
                arc = Arc(angle = self.path_angles[i])
                arc.scale(arc_radius)
                arc.rotate(rotation)
                arc.shift(bend_point)
                angle_arcs.append(arc)
            thetas = []
            for i in [index+1, index+2]:
                theta = TexMobject("\\theta_%d"%i)
                theta.scale(0.5/self.zoom_factor)
                vert = UP if i == index+1 else DOWN
                horiz = rotate_vector(vert, np.pi/2)
                theta.next_to(
                    Point(bend_point), 
                    horiz, 
                    buff = 0.01
                )
                theta.shift(1.5*arc_radius*vert)
                thetas.append(theta)
            figure_marks = [line] + angle_arcs + thetas                

            self.play(ApplyMethod(
                little_square.shift,
                bend_point - little_square.get_center(),
                run_time = 2
            ))
            self.play(*map(ShowCreation, figure_marks))
            self.dither()
            equation_frame = little_square.copy()
            equation_frame.scale(0.5)
            equation_frame.shift(
                little_square.get_corner(UP+RIGHT) - \
                equation_frame.get_corner(UP+RIGHT)
            )
            equation_frame.scale_in_place(0.9)
            self.show_snells(index+1, equation_frame)
            self.remove(*figure_marks)
        self.disactivate_zooming()
Exemplo n.º 54
0
    def solve_energy(self):
        loss_in_potential = TextMobject("Loss in potential: ")
        loss_in_potential.shift(2*UP)
        potential = TexMobject("m g y".split())
        potential.next_to(loss_in_potential)
        kinetic = TexMobject([
            "\\dfrac{1}{2}","m","v","^2","="
        ])
        kinetic.next_to(potential, LEFT)
        nudge = 0.1*UP
        kinetic.shift(nudge)
        loss_in_potential.shift(nudge)
        ms = Mobject(kinetic.split()[1], potential.split()[0])
        two = TexMobject("2")
        two.shift(ms.split()[1].get_center())
        half = kinetic.split()[0]
        sqrt = TexMobject("\\sqrt{\\phantom{2mg}}")
        sqrt.shift(potential.get_center())
        nudge = 0.2*LEFT
        sqrt.shift(nudge)
        squared = kinetic.split()[3]
        equals = kinetic.split()[-1]
        new_eq = equals.copy().next_to(kinetic.split()[2])

        self.play(
            Transform(
                Point(loss_in_potential.get_left()),
                loss_in_potential
            ),
            *map(GrowFromCenter, potential.split())
        )
        self.dither(2)
        self.play(
            FadeOut(loss_in_potential),
            GrowFromCenter(kinetic)
        )
        self.dither(2)
        self.play(ApplyMethod(ms.shift, 5*UP))
        self.dither()
        self.play(Transform(
            half, two, 
            path_func = counterclockwise_path()
        ))
        self.dither()
        self.play(
            Transform(
                squared, sqrt, 
                path_func = clockwise_path()
            ),
            Transform(equals, new_eq)
        )
        self.dither(2)
Exemplo n.º 55
0
    def standard_basis_comparison(self, label_anims, scalar_anims):
        everything = self.get_mobjects()
        everything.remove(self.sum_vector)
        everything = VMobject(*everything)
        alt_coords = [a.mobject for a in scalar_anims]
        array = Matrix([
            mob.copy().highlight(color)
            for mob, color in zip(
                alt_coords, 
                [self.vector1_color, self.vector2_color]
            )
        ])
        array.scale(0.8)
        array.to_edge(UP)
        array.shift(RIGHT)
        brackets = array.get_brackets()

        anims = [
            Transform(*pair)
            for pair in zip(alt_coords, array.get_mob_matrix().flatten())
        ]
        # anims += [
        #     FadeOut(a.mobject)
        #     for a in label_anims
        # ]
        self.play(*anims + [Write(brackets)])
        self.dither()
        self.remove(brackets, *alt_coords)
        self.add(array)
        self.play(
            FadeOut(everything), 
            Animation(array),
        )

        self.add_axes(animate = True)
        ij_array, x_line, y_line = self.vector_to_coords(
            self.sum_vector, integer_labels = False
        )
        self.add(ij_array, x_line, y_line)
        x, y = ij_array.get_mob_matrix().flatten()
        self.play(
            ApplyMethod(x.highlight, X_COLOR),
            ApplyMethod(y.highlight, Y_COLOR),
        )
        neq = TexMobject("\\neq")
        neq.next_to(array)
        self.play(
            ApplyMethod(ij_array.next_to, neq),
            Write(neq)
        )
        self.dither()
Exemplo n.º 56
0
    def construct(self):
        two_dot = TexMobject("2\\cdot")
        equals = TexMobject("=")
        self.add_axes()
        v = self.add_vector([3, 1])
        v_coords, vx_line, vy_line = self.vector_to_coords(v, cleanup = False)
        self.play(ApplyMethod(v_coords.to_edge, UP))
        two_dot.next_to(v_coords, LEFT)
        equals.next_to(v_coords, RIGHT)
        two_v = self.add_vector([6, 2], animate = False)
        self.remove(two_v)
        self.play(
            Transform(v.copy(), two_v), 
            Write(two_dot, run_time = 1)
        )
        two_v_coords, two_v_x_line, two_v_y_line = self.vector_to_coords(
            two_v, cleanup = False
        )
        self.play(
            ApplyMethod(two_v_coords.next_to, equals, RIGHT),
            Write(equals, run_time = 1)
        )
        self.dither(2)

        x, y = v_coords.get_mob_matrix().flatten()
        two_v_elems = two_v_coords.get_mob_matrix().flatten()
        x_sym, y_sym = map(TexMobject, ["x", "y"])
        two_x_sym, two_y_sym = map(TexMobject, ["2x", "2y"])
        VMobject(x_sym, two_x_sym).highlight(X_COLOR)
        VMobject(y_sym, two_y_sym).highlight(Y_COLOR)
        syms = [x_sym, y_sym, two_x_sym, two_y_sym]
        VMobject(*syms).scale(VECTOR_LABEL_SCALE_VAL)
        for sym, num in zip(syms, [x, y] + list(two_v_elems)):
            sym.move_to(num)
        self.play(
            Transform(x, x_sym),
            Transform(y, y_sym),
            FadeOut(VMobject(*two_v_elems))
        )
        self.dither()
        self.play(
            Transform(
                VMobject(two_dot.copy(), x.copy()),
                two_x_sym
            ),
            Transform(
                VMobject(two_dot.copy(), y.copy() ),
                two_y_sym
            )
        )
        self.dither(2)
Exemplo n.º 57
0
    def show_dfs(self):
        dx_lines = VGroup()
        df_lines = VGroup()
        df_dx_groups = VGroup()
        df_labels = VGroup()
        for i, v_line1, v_line2 in zip(it.count(1), self.v_lines, self.v_lines[1:]):
            dx_line = Line(
                v_line1.get_bottom(),
                v_line2.get_bottom(),
                color = GREEN
            )
            dx_line.move_to(v_line1.get_top(), LEFT)
            dx_lines.add(dx_line)

            df_line = Line(
                dx_line.get_right(),
                v_line2.get_top(),
                color = YELLOW
            )
            df_lines.add(df_line)
            df_label = TexMobject("df_%d"%i)
            df_label.highlight(YELLOW)
            df_label.scale(0.8)
            df_label.next_to(df_line.get_center(), UP+LEFT, MED_LARGE_BUFF)
            df_arrow = Arrow(
                df_label.get_bottom(),
                df_line.get_center(),
                buff = SMALL_BUFF,
            )
            df_line.label = df_label
            df_line.arrow = df_arrow
            df_labels.add(df_label)

            df_dx_groups.add(VGroup(df_line, dx_line))

        for brace, dx_line, df_line in zip(self.braces, dx_lines, df_lines):
            self.play(
                VGroup(brace, brace.dx).next_to,
                dx_line, DOWN, SMALL_BUFF,
                FadeIn(dx_line),
            )
            self.play(ShowCreation(df_line))
            self.play(
                ShowCreation(df_line.arrow),
                Write(df_line.label)
            )
            self.dither(2)

        self.df_dx_groups = df_dx_groups
        self.df_labels = df_labels
Exemplo n.º 58
0
 def get_number_mob(self, num):
     result = VGroup()
     place = 0
     max_place = self.max_place
     while place < max_place:
         digit = TexMobject(str(self.get_place_num(num, place)))
         if place >= len(self.digit_place_colors):
             self.digit_place_colors += self.digit_place_colors
         digit.highlight(self.digit_place_colors[place])
         digit.scale(self.num_scale_factor)
         digit.next_to(result, LEFT, buff = SMALL_BUFF, aligned_edge = DOWN)
         result.add(digit)
         place += 1
     return result
Exemplo n.º 59
0
    def construct(self):
        sine = TexMobject("\\sin(x)")
        triangle = Polygon(ORIGIN, 2*RIGHT, 2*RIGHT+UP)
        arrow = DoubleArrow(LEFT, RIGHT)        
        sine.next_to(arrow, LEFT)
        triangle.next_to(arrow, RIGHT)

        q_mark = TextMobject("?").scale(1.5)
        q_mark.next_to(arrow, UP)

        self.add(sine)
        self.play(ShowCreation(arrow))
        self.play(ShowCreation(triangle))
        self.play(Write(q_mark))
        self.dither()
Exemplo n.º 60
0
 def get_axis_labels(self, x_label = "x", y_label = "y"):
     x_axis, y_axis = self.get_axes().split()
     quads = [
         (x_axis, x_label, UP, RIGHT),
         (y_axis, y_label, RIGHT, UP),
     ]
     labels = VGroup()
     for axis, tex, vect, edge in quads:
         label = TexMobject(tex)
         label.add_background_rectangle()
         label.next_to(axis, vect)
         label.to_edge(edge)
         labels.add(label)
     self.axis_labels = labels
     return labels