Пример #1
0
    def add_plane(self):
        plane = ComplexPlane(
            unit_size=self.unit_size,
            center_point=self.plane_center,
            stroke_width=2,
        )
        plane.axes.set_stroke(width=4)
        coordinate_labels = VGroup()
        for x in self.x_label_range:
            if x == 0:
                continue
            coord = TexMobject(str(x))
            coord.scale(0.75)
            coord.next_to(plane.coords_to_point(x, 0), DOWN, SMALL_BUFF)
            coord.add_background_rectangle()
            coordinate_labels.add(coord)
        for y in self.y_label_range:
            if y == 0:
                continue
            coord = TexMobject("%di" % y)
            coord.scale(0.75)
            coord.next_to(plane.coords_to_point(0, y), LEFT, SMALL_BUFF)
            coord.add_background_rectangle()
            coordinate_labels.add(coord)
        self.add(plane, coordinate_labels)

        self.plane = plane
        self.plane.coordinate_labels = coordinate_labels
Пример #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
Пример #3
0
    def construct(self):
        derivative = TexMobject(
            "\\frac{d(a^t)}{dt} =", "a^t \\ln(a)"
        )
        derivative[0][3].highlight(YELLOW)
        derivative[1][1].highlight(YELLOW)
        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)

        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)
        # randy.look_at(question)

        self.add(derivative, brace, question)
Пример #4
0
    def construct(self):
        pascals_triangle = PascalsTriangle()
        pascals_triangle.scale(0.5)
        final_triangle = PascalsTriangle()
        final_triangle.fill_with_n_choose_k()
        pascals_triangle.to_corner(UP+LEFT)
        final_triangle.scale(0.7)
        final_triangle.to_edge(UP)
        equation = TexMobject([
            "{n \\choose k}",
            " = \\dfrac{n!}{(n-k)!k!}"
        ])
        equation.scale(0.5)
        equation.to_corner(UP+RIGHT)
        n_choose_k, formula = equation.split()
        words = TextMobject("Seemingly unrelated")
        words.shift(2*DOWN)
        to_remove = VMobject(*words.split()[:-7])

        self.add(pascals_triangle, n_choose_k, formula)
        self.play(Write(words))
        self.dither()
        self.play(
            Transform(pascals_triangle, final_triangle),
            Transform(n_choose_k, final_triangle),
            FadeOut(formula),
            ApplyMethod(to_remove.shift, 5*DOWN)
        )
        self.dither()
Пример #5
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
Пример #6
0
    def show_angles(self, ring):
        ring_center = ring.get_center()
        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in self.start_point, self.end_point:
            line = Line(point, ring_center, color=GREY)
            angle = np.pi / 2 - np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius=0.5).rotate(np.pi / 2)
            if point is self.end_point:
                arc.rotate(np.pi)
            theta = TexMobject("\\theta_%d" % counter.next())
            theta.scale(0.5)
            theta.shift(2 * arc.get_center())
            arc.shift(ring_center)
            theta.shift(ring_center)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2 * UP, 2 * DOWN)
        vert_line.shift(ring_center)
        top_spring, bottom_spring = self.start_springs.split()

        self.play(Transform(ring, Point(ring_center)),
                  Transform(top_spring, lines[0]),
                  Transform(bottom_spring, lines[1]))
        self.play(ShowCreation(vert_line))
        anims = []
        for arc, theta in zip(arcs, thetas):
            anims += [ShowCreation(arc), GrowFromCenter(theta)]
        self.play(*anims)
        self.wait()
Пример #7
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)
Пример #8
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
Пример #9
0
    def get_vector_label(self,
                         vector,
                         label,
                         direction="left",
                         rotate=False,
                         color=None,
                         label_scale_factor=VECTOR_LABEL_SCALE_FACTOR):
        if not isinstance(label, TexMobject):
            if len(label) == 1:
                label = "\\vec{\\textbf{%s}}" % label
            label = TexMobject(label)
            if color is None:
                color = vector.get_color()
            label.highlight(color)
        label.scale(label_scale_factor)
        label.add_background_rectangle()

        angle = vector.get_angle()
        if not rotate:
            label.rotate(-angle)
        if direction is "left":
            label.shift(-label.get_bottom() + 0.1 * UP)
        else:
            label.shift(-label.get_top() + 0.1 * DOWN)
        label.rotate(angle)
        label.shift((vector.get_end() - vector.get_start()) / 2)
        return label
Пример #10
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()
Пример #11
0
    def construct(self):
        v_tex = "\\vec{\\textbf{v}}"
        eq = TexMobject("A", v_tex, "=", "\\lambda", v_tex)
        eq.highlight_by_tex(v_tex, YELLOW)
        eq.highlight_by_tex("\\lambda", MAROON_B)
        eq.scale(3)
        eq.add_background_rectangle()
        eq.shift(2 * DOWN)

        title = TextMobject("Eigen",
                            "vectors \\\\",
                            "Eigen",
                            "values",
                            arg_separator="")
        title.scale(2.5)
        title.to_edge(UP)
        # title.highlight_by_tex("Eigen", MAROON_B)
        title[0].highlight(YELLOW)
        title[2].highlight(MAROON_B)
        title.add_background_rectangle()

        self.add_vector([-1, 1], color=YELLOW, animate=False)
        self.apply_transposed_matrix([[3, 0], [1, 2]])
        self.plane.fade()
        self.remove(self.j_hat)
        self.add(eq, title)
Пример #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)
Пример #13
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")
Пример #14
0
    def construct(self):
        self.setup()
        symbols = TexMobject(list(self.symbols_str))
        symbols.scale(1.5)
        symbols.to_edge(UP)
        a, b, c = None, None, None
        for mob, letter in zip(symbols.split(), self.symbols_str):
            if letter == "A":
                a = mob
            elif letter == "B":
                b = mob
            elif letter == "C":
                c = mob

        symbols.add_background_rectangle()
        self.add_foreground_mobject(symbols)

        brace = Brace(c, DOWN)
        words = TextMobject("Apply this transformation")
        words.add_background_rectangle()
        words.next_to(brace, DOWN)
        brace.add(words)

        self.play(Write(brace, run_time=1))
        self.add_foreground_mobject(brace)

        last = VectorizedPoint()
        for t_matrix, sym in zip(self.t_matrices, [c, b, a]):
            self.play(brace.next_to, sym, DOWN, sym.highlight, YELLOW,
                      last.highlight, WHITE)
            self.apply_transposed_matrix(t_matrix, run_time=1)
            last = sym
        self.wait()
Пример #15
0
    def get_cosine_second_derivative(self):
        if not hasattr(self, "cosine_derivative"):
            self.get_cosine_derivative()
        second_deriv = TexMobject(
            "{d^2(", "\\cos", ")", "\\over", "dx}", 
            "(", "0", ")",
        )
        second_deriv.highlight_by_tex("cos", self.colors[0])
        second_deriv.highlight_by_tex("-\\cos", self.colors[2])
        second_deriv.scale(0.75)
        second_deriv.add_background_rectangle()
        second_deriv.next_to(
            self.cosine_derivative, DOWN,
            buff = MED_LARGE_BUFF,
            aligned_edge = LEFT
        )
        rhs = TexMobject("=", "-\\cos(0)", "=", "-1")
        rhs.highlight_by_tex("cos", self.colors[2])
        rhs.scale(0.8)
        rhs.next_to(
            second_deriv, RIGHT, 
            align_using_submobjects = True
        )

        self.cosine_second_derivative = VGroup(second_deriv, rhs)
        return self.cosine_second_derivative
Пример #16
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)
Пример #17
0
    def add_polygons(self):
        a = self.i_hat.get_end()[0]*RIGHT
        b = self.j_hat.get_end()[0]*RIGHT
        c = self.i_hat.get_end()[1]*UP
        d = self.j_hat.get_end()[1]*UP

        shapes_colors_and_tex = [
            (Polygon(ORIGIN, a, a+c), TEAL, "bd/2"),
            (Polygon(ORIGIN, d+b, d), TEAL, "\\dfrac{bd}{2}"),
            (Polygon(a+c, a+b+c, a+b+c+d), MAROON, "\\dfrac{ac}{2}"),
            (Polygon(b+d, a+b+c+d, b+c+d), MAROON, "ac/2"),
            (Polygon(a, a+b, a+b+c, a+c), PINK, "bc"),
            (Polygon(d, d+b, d+b+c, d+c), PINK, "bc"),
        ]
        everyone = VMobject()
        for shape, color, tex in shapes_colors_and_tex:
            shape.set_stroke(width = 0)
            shape.set_fill(color = color, opacity = 0.7)
            tex_mob = TexMobject(tex)
            tex_mob.scale(0.7)
            tex_mob.move_to(shape.get_center_of_mass())
            everyone.add(shape, tex_mob)
        self.play(FadeIn(
            everyone, 
            submobject_mode = "lagged_start",
            run_time = 1
        ))
Пример #18
0
    def construct(self):
        derivative = TexMobject("\\frac{d(a^t)}{dt} =", "a^t \\ln(a)")
        derivative[0][3].highlight(YELLOW)
        derivative[1][1].highlight(YELLOW)
        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)

        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)
        # randy.look_at(question)

        self.add(derivative, brace, question)
Пример #19
0
    def get_vector_label(self, vector, label, 
                         direction = "left", 
                         rotate = False,
                         color = None, 
                         label_scale_factor = VECTOR_LABEL_SCALE_FACTOR):
        if not isinstance(label, TexMobject):
            if len(label) == 1:
                label = "\\vec{\\textbf{%s}}"%label
            label = TexMobject(label)
            if color is None:
                color = vector.get_color()
            label.highlight(color)
        label.scale(label_scale_factor)
        label.add_background_rectangle()

        angle = vector.get_angle()
        if not rotate:
            label.rotate(-angle)
        if direction is "left":
            label.shift(-label.get_bottom() + 0.1*UP)
        else:
            label.shift(-label.get_top() + 0.1*DOWN)
        label.rotate(angle)
        label.shift((vector.get_end() - vector.get_start())/2)
        return label
Пример #20
0
    def increase_radius(self):
        radius_mobs = VGroup(
            self.radius_line, self.radius_brace, self.radius_label
        )
        nudge_line = Line(
            self.radius_line.get_right(),
            self.radius_line.get_right() + self.dR*RIGHT,
            color = self.radius_line.get_color()
        )
        nudge_arrow = Arrow(
            nudge_line.get_center() + 0.5*RIGHT+DOWN,
            nudge_line.get_center(),
            color = YELLOW,
            buff = 0.025,
            tip_length = 0.2,
        )
        nudge_label = TexMobject("%.01f"%self.dR)
        nudge_label.scale(0.75)
        nudge_label.next_to(nudge_arrow.get_start(), DOWN)

        radius_mobs.add(nudge_line, nudge_arrow, nudge_label)

        outer_ring = self.get_outer_ring()

        self.play(ShowCreation(nudge_line))
        self.play(
            ShowCreation(nudge_arrow),
            Write(nudge_label)
        )
        self.dither()
        self.play(
            FadeIn(outer_ring),
            *map(Animation, radius_mobs)
        )
        return outer_ring
Пример #21
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()
Пример #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()
Пример #23
0
    def construct(self):
        v_tex = "\\vec{\\textbf{v}}"
        eq = TexMobject("A", v_tex, "=", "\\lambda", v_tex)
        eq.highlight_by_tex(v_tex, YELLOW)
        eq.highlight_by_tex("\\lambda", MAROON_B)
        eq.scale(3)
        eq.add_background_rectangle()
        eq.shift(2*DOWN)        

        title = TextMobject(
            "Eigen", "vectors \\\\",
            "Eigen", "values"
        , arg_separator = "")
        title.scale(2.5)
        title.to_edge(UP)
        # title.highlight_by_tex("Eigen", MAROON_B)
        title[0].highlight(YELLOW)
        title[2].highlight(MAROON_B)
        title.add_background_rectangle()


        self.add_vector([-1, 1], color = YELLOW, animate = False)
        self.apply_transposed_matrix([[3, 0], [1, 2]])        
        self.plane.fade()
        self.remove(self.j_hat)
        self.add(eq, title)
Пример #24
0
    def view_as_complex_number(self):
        imag_coords = VGroup()
        for y in range(-4, 5, 2):
            if y == 0:
                continue
            label = TexMobject("%di" % y)
            label.add_background_rectangle()
            label.scale(0.75)
            label.next_to(self.plane.coords_to_point(0, y), LEFT, SMALL_BUFF)
            imag_coords.add(label)
        tuple_label = self.example_tuple_label
        new_label = TexMobject("2+i")
        new_label.add_background_rectangle()
        new_label.next_to(
            self.example_dot,
            DOWN + RIGHT,
            buff=0,
        )

        self.play(Write(imag_coords))
        self.dither()
        self.play(FadeOut(tuple_label))
        self.play(FadeIn(new_label))
        self.dither(2)

        self.example_label = new_label
        self.plane.coordinate_labels.add(*imag_coords)
Пример #25
0
 def get_arrow_x_equals_0_group(self):
     arrow = Arrow(LEFT, RIGHT)
     x_equals_0 = TexMobject("x = 0")
     x_equals_0.scale(0.75)
     x_equals_0.next_to(arrow.get_center(), UP, 2*SMALL_BUFF)
     x_equals_0.shift(SMALL_BUFF*LEFT)
     return VGroup(arrow, x_equals_0)
Пример #26
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")
Пример #27
0
 def construct(self):
     for char, color in zip(["\\imath", "\\jmath", "k"], [X_COLOR, Y_COLOR, Z_COLOR]):
         sym = TexMobject("{\\hat{%s}}"%char)
         sym.scale(3)
         sym.highlight(color)
         self.play(Write(sym))
         self.dither()
         self.clear()
Пример #28
0
    def ask_about_derivative(self):
        deriv_q = TexMobject("{df ", "\\over dx}", "=", "???")
        deriv_q.scale(self.tex_scale_factor)
        deriv_q.next_to(self.func_mob, DOWN)
        self.play(Write(deriv_q))
        self.dither()

        self.deriv_q = deriv_q
Пример #29
0
 def construct(self):
     tex = TexMobject("f(X, X)", "=X")
     tex.highlight_by_tex("=X", BLUE)
     tex.scale(2)
     self.play(Write(tex[0]))
     self.dither(2)
     self.play(Write(tex[1]))
     self.dither(2)
Пример #30
0
    def construct(self):
        dated_events = [
            {
                "date" : 1696, 
                "text": "Johann Bernoulli poses Brachistochrone problem",
                "picture" : "Johann_Bernoulli2"
            },
            {
                "date" : 1662, 
                "text" : "Fermat states his principle of least time",
                "picture" : "Pierre_de_Fermat"
            }
        ]
        speical_dates = [2016] + [
            obj["date"] for obj in dated_events
        ]
        centuries = range(1600, 2100, 100)
        timeline = NumberLine(
            numerical_radius = 300,
            number_at_center = 1800,
            unit_length_to_spatial_width = SPACE_WIDTH/100,
            tick_frequency = 10,
            numbers_with_elongated_ticks = centuries
        )
        timeline.add_numbers(*centuries)
        centers = [
            Point(timeline.number_to_point(year))
            for year in speical_dates
        ]
        timeline.add(*centers)
        timeline.shift(-centers[0].get_center())

        self.add(timeline)
        self.dither()
        run_times = iter([3, 1])
        for point, event in zip(centers[1:], dated_events):
            self.play(ApplyMethod(
                timeline.shift, -point.get_center(), 
                run_time = run_times.next()
            ))
            picture = ImageMobject(event["picture"], invert = False)
            picture.scale_to_fit_width(2)
            picture.to_corner(UP+RIGHT)
            event_mob = TextMobject(event["text"])
            event_mob.shift(2*LEFT+2*UP)
            date_mob = TexMobject(str(event["date"]))
            date_mob.scale(0.5)
            date_mob.shift(0.6*UP)
            line = Line(event_mob.get_bottom(), 0.2*UP)
            self.play(
                ShimmerIn(event_mob),
                ShowCreation(line),
                ShimmerIn(date_mob)
            )
            self.play(FadeIn(picture))
            self.dither(3)
            self.play(*map(FadeOut, [event_mob, date_mob, line, picture]))
Пример #31
0
    def write_function(self):
        func_mob = TexMobject("f(x) = ", "\\sin(x)", "+", "x^2")
        func_mob.scale(self.tex_scale_factor)
        func_mob.highlight_by_tex("\\sin(x)", SINE_COLOR)
        func_mob.highlight_by_tex("x^2", X_SQUARED_COLOR)
        func_mob.to_corner(UP + RIGHT)
        self.add(func_mob)

        self.func_mob = func_mob
Пример #32
0
 def add_brackets(self):
     bracket_pair = TexMobject("\\big[ \\big]")
     bracket_pair.scale(2)
     bracket_pair.stretch_to_fit_height(self.get_height() + 0.5)
     l_bracket, r_bracket = bracket_pair.split()
     l_bracket.next_to(self, LEFT)
     r_bracket.next_to(self, RIGHT)
     self.add(l_bracket, r_bracket)
     self.brackets = VMobject(l_bracket, r_bracket)
     return self
Пример #33
0
 def add_brackets(self):
     bracket_pair = TexMobject("\\big[ \\big]")
     bracket_pair.scale(2)
     bracket_pair.stretch_to_fit_height(self.get_height() + 0.5)
     l_bracket, r_bracket = bracket_pair.split()
     l_bracket.next_to(self, LEFT)
     r_bracket.next_to(self, RIGHT)
     self.add(l_bracket, r_bracket)
     self.brackets = VMobject(l_bracket, r_bracket)
     return self
Пример #34
0
    def construct(self):
        point_a = 3*LEFT+3*UP
        point_b = 1.5*RIGHT+3*DOWN
        midpoint = ORIGIN

        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in point_a, point_b:
            line = Line(point, midpoint, color = RED_D)
            angle = np.pi/2-np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius = 0.5).rotate(np.pi/2)
            if point is point_b:
                arc.rotate(np.pi)
                line.reverse_points()
            theta = TexMobject("\\theta_%d"%counter.next())
            theta.scale(0.5)
            theta.shift(2*arc.get_center())
            arc.shift(midpoint)
            theta.shift(midpoint)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2*UP, 2*DOWN)
        vert_line.shift(midpoint)
        path = Mobject(*lines).ingest_submobjects()
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.add(glass)
        equation = TexMobject([
            "\\dfrac{\\sin(\\theta_1)}{v_{\\text{air}}}",
            "=",            
            "\\dfrac{\\sin(\\theta_2)}{v_{\\text{water}}}",
        ])
        equation.to_corner(UP+RIGHT)
        exp1, equals, exp2 = equation.split()
        snells_law = TextMobject("Snell's Law:")
        snells_law.highlight(YELLOW)
        snells_law.to_edge(UP)

        self.play(ShimmerIn(snells_law))
        self.dither()
        self.play(ShowCreation(path))
        self.play(self.photon_run_along_path(path))
        self.dither()
        self.play(ShowCreation(vert_line))
        self.play(*map(ShowCreation, arcs))
        self.play(*map(GrowFromCenter, thetas))
        self.dither()
        self.play(ShimmerIn(exp1))
        self.dither()
        self.play(*map(ShimmerIn, [equals, exp2]))
        self.dither()
Пример #35
0
    def write_function(self):
        brace = Brace(self.det_text, DOWN)
        number_text = brace.get_text("Number")
        self.play(Transform(self.title, self.title.not_real))
        self.dither()
        self.play(FadeOut(self.definitions))
        self.play(GrowFromCenter(brace), Write(number_text))
        self.dither()

        x, y, z = variables = map(TexMobject, "xyz")
        for var, entry in zip(variables, self.u_entries):
            var.scale(0.8)
            var.move_to(entry)
            entry.target = var
        brace.target = Brace(z)
        brace.target.stretch_to_fit_width(0.5)
        number_text.target = brace.target.get_text("Variable")
        v_brace = Brace(self.matrix.get_mob_matrix()[0, 1], UP)
        w_brace = Brace(self.matrix.get_mob_matrix()[0, 2], UP)
        for vect_brace, tex in (v_brace, self.v_tex), (w_brace, self.w_tex):
            vect_brace.stretch_to_fit_width(brace.target.get_width())
            new_tex = tex.copy()
            vect_brace.put_at_tip(new_tex)
            vect_brace.tex = new_tex
        func_tex = TexMobject("f\\left(%s\\right)" %
                              matrix_to_tex_string(list("xyz")))
        func_tex.scale(0.7)
        func_input = Matrix(list("xyz"))
        func_input_template = VGroup(*func_tex[3:-2])
        func_input.scale_to_fit_height(func_input_template.get_height())
        func_input.next_to(VGroup(*func_tex[:3]), RIGHT)
        VGroup(*func_tex[-2:]).next_to(func_input, RIGHT)
        func_tex[0].scale_in_place(1.5)

        func_tex = VGroup(VGroup(*[func_tex[i] for i in 0, 1, 2, -2, -1]),
                          func_input)
        func_tex.next_to(self.equals, LEFT)

        self.play(
            FadeOut(self.title), FadeOut(self.triple_cross),
            *[Transform(mob, mob.target) for mob in [brace, number_text]])
        self.play(*[Transform(mob, mob.target) for mob in self.u_entries])
        self.play(*[
            Write(VGroup(vect_brace, vect_brace.tex))
            for vect_brace in v_brace, w_brace
        ])
        self.dither()
        self.play(Write(func_tex))
        self.dither()

        self.func_tex = func_tex
        self.variables_text = VGroup(brace, number_text)
Пример #36
0
    def construct(self):
        point_a = 3*LEFT+3*UP
        point_b = 1.5*RIGHT+3*DOWN
        midpoint = ORIGIN

        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in point_a, point_b:
            line = Line(point, midpoint, color = RED_D)
            angle = np.pi/2-np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius = 0.5).rotate(np.pi/2)
            if point is point_b:
                arc.rotate(np.pi)
                line.reverse_points()
            theta = TexMobject("\\theta_%d"%counter.next())
            theta.scale(0.5)
            theta.shift(2*arc.get_center())
            arc.shift(midpoint)
            theta.shift(midpoint)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2*UP, 2*DOWN)
        vert_line.shift(midpoint)
        path = Mobject(*lines).ingest_submobjects()
        glass = Region(lambda x, y : y < 0, color = BLUE_E)
        self.add(glass)
        equation = TexMobject([
            "\\dfrac{\\sin(\\theta_1)}{v_{\\text{air}}}",
            "=",            
            "\\dfrac{\\sin(\\theta_2)}{v_{\\text{water}}}",
        ])
        equation.to_corner(UP+RIGHT)
        exp1, equals, exp2 = equation.split()
        snells_law = TextMobject("Snell's Law:")
        snells_law.highlight(YELLOW)
        snells_law.to_edge(UP)

        self.play(ShimmerIn(snells_law))
        self.wait()
        self.play(ShowCreation(path))
        self.play(self.photon_run_along_path(path))
        self.wait()
        self.play(ShowCreation(vert_line))
        self.play(*map(ShowCreation, arcs))
        self.play(*map(GrowFromCenter, thetas))
        self.wait()
        self.play(ShimmerIn(exp1))
        self.wait()
        self.play(*map(ShimmerIn, [equals, exp2]))
        self.wait()
Пример #37
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()
Пример #38
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.wait()
            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()
Пример #39
0
    def show_df_algebraically(self):
        deriv = TexMobject("df", "=", "d(\\sin(x))", "+", "d(x^2)")
        deriv.scale(self.tex_scale_factor)
        deriv.next_to(self.deriv_q, DOWN, buff=MED_LARGE_BUFF)
        deriv.highlight_by_tex("df", SUM_COLOR)
        deriv.highlight_by_tex("d(\\sin(x))", SINE_COLOR)
        deriv.highlight_by_tex("d(x^2)", X_SQUARED_COLOR)

        self.play(FocusOn(self.deriv_q))
        self.play(ReplacementTransform(self.deriv_q[0].copy(), deriv[0]))
        self.play(Write(VGroup(*deriv[1:])))
        self.dither()

        self.deriv = deriv
Пример #40
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
Пример #41
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
Пример #42
0
 def get_number_mob(self, num):
     result = VGroup()
     place = 0
     while num > 0:
         digit = TexMobject(str(num % self.base))
         if place >= len(self.power_colors):
             self.power_colors += self.power_colors
         digit.highlight(self.power_colors[place])
         digit.scale(self.num_scale_factor)
         digit.next_to(result, LEFT, buff = SMALL_BUFF, aligned_edge = DOWN)
         result.add(digit)
         num /= self.base
         place += 1
     return result
Пример #43
0
 def get_number_mobjects(self, *numbers):
     # TODO, handle decimals
     if len(numbers) == 0:
         numbers = self.default_numbers_to_display()
     result = []
     for number in numbers:
         mob = TexMobject(str(int(number)))
         vert_scale = 2 * self.tick_size / mob.get_height()
         hori_scale = self.tick_frequency * self.unit_length_to_spatial_width / mob.get_width()
         mob.scale(min(vert_scale, hori_scale))
         mob.shift(self.number_to_point(number))
         mob.shift(self.get_vertical_number_offset())
         result.append(mob)
     return result
Пример #44
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.wait(2)

        self.df_dx_groups = df_dx_groups
        self.df_labels = df_labels
Пример #45
0
 def get_coordinate_labels(self, x_vals=None, y_vals=None):
     result = []
     nudge = 0.1 * (DOWN + RIGHT)
     if x_vals == None and y_vals == None:
         x_vals = range(-int(self.x_radius), int(self.x_radius))
         y_vals = range(-int(self.y_radius), int(self.y_radius))
     for index, vals in zip([0, 1], [x_vals, y_vals]):
         num_pair = [0, 0]
         for val in vals:
             num_pair[index] = val
             point = self.num_pair_to_point(num_pair)
             num = TexMobject(str(val))
             num.scale(self.number_scale_factor)
             num.shift(point - num.get_corner(UP + LEFT) + nudge)
             result.append(num)
     return result
Пример #46
0
def get_det_text(matrix, determinant = None):
    parens = TexMobject(["(", ")"])
    parens.scale(2)
    parens.stretch_to_fit_height(matrix.get_height())
    l_paren, r_paren = parens.split()
    l_paren.next_to(matrix, LEFT, buff = 0.1)
    r_paren.next_to(matrix, RIGHT, buff = 0.1)
    det = TextMobject("det").next_to(l_paren, LEFT, buff = 0.1)
    det.add_background_rectangle()
    det_text = VMobject(det, l_paren, r_paren)
    if determinant is not None:
        eq = TexMobject("=")
        eq.next_to(r_paren, RIGHT, buff = 0.1)
        result = TexMobject(str(determinant))
        result.next_to(eq, RIGHT, buff = 0.2)
        det_text.add(eq, result)
    return det_text
Пример #47
0
    def construct(self):
        v_color = MAROON_C
        w_color = BLUE

        definition = TextMobject("""
            The ``span'' of $\\vec{\\textbf{v}}$ and 
            $\\vec{\\textbf{w}}$ is the \\\\ set of all their
            linear combinations.
        """)
        definition.scale_to_fit_width(2*SPACE_WIDTH-1)
        definition.to_edge(UP)
        def_mobs = np.array(definition.split())
        VMobject(*def_mobs[4:4+4]).highlight(PINK)
        VMobject(*def_mobs[11:11+2]).highlight(v_color)
        VMobject(*def_mobs[16:16+2]).highlight(w_color)
        VMobject(*def_mobs[-19:-1]).highlight(YELLOW)

        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(definition, DOWN, buff = 1)

        vary_words = TextMobject(
            "Let $a$ and $b$ vary \\\\ over all real numbers"
        )
        vary_words.scale(1.5)
        vary_words.next_to(equation, DOWN, buff = 2)
        arrows = [
            Arrow(vary_words, letter)
            for letter in a, b
        ]

        self.play(Write(definition))
        self.play(Write(equation))
        self.dither()
        self.play(
            FadeIn(vary_words),
            ShowCreation(VMobject(*arrows))
        )
        self.dither()
Пример #48
0
    def write_second_derivative(self):
        ddf_over_dx_squared = TexMobject(
            "{d(df)", "\\over", "(dx)^2}"
        )
        ddf_over_dx_squared.scale(0.8)
        ddf_over_dx_squared.move_to(self.ddf, RIGHT)
        ddf_over_dx_squared.highlight_by_tex("df", self.ddf.get_color())
        parens = VGroup(
            ddf_over_dx_squared[0][1],
            ddf_over_dx_squared[0][4],
            ddf_over_dx_squared[2][0],
            ddf_over_dx_squared[2][3],
        )

        right_shifter = ddf_over_dx_squared[0][0]
        left_shifter = ddf_over_dx_squared[2][4]

        exp_two = TexMobject("2")
        exp_two.highlight(self.ddf.get_color())
        exp_two.scale(0.5)
        exp_two.move_to(right_shifter.get_corner(UP+RIGHT), LEFT)
        exp_two.shift(MED_SMALL_BUFF*RIGHT)
        pre_exp_two = VGroup(ddf_over_dx_squared[0][2])

        self.play(
            Write(ddf_over_dx_squared.get_part_by_tex("over")),
            *[
                ReplacementTransform(
                    mob, 
                    ddf_over_dx_squared.get_part_by_tex(tex),
                    path_arc = -np.pi/2,                    
                )
                for mob, tex in (self.ddf, "df"), (self.dx_squared, "dx")
            ]
        )
        self.dither(2)
        self.play(FadeOut(parens))
        self.play(
            left_shifter.shift, 0.2*LEFT,
            right_shifter.shift, 0.2*RIGHT,
            ReplacementTransform(pre_exp_two, exp_two),
            ddf_over_dx_squared.get_part_by_tex("over").scale_in_place, 0.8
        )
        self.dither(2)
Пример #49
0
 def get_coordinate_labels(self, *numbers):
     result = []
     nudge = 0.1*(DOWN+RIGHT)
     if len(numbers) == 0:
         numbers = range(-int(self.x_radius), int(self.x_radius))
         numbers += [
             complex(0, y)
             for y in range(-int(self.y_radius), int(self.y_radius))
         ]
     for number in numbers:
         point = self.number_to_point(number)
         if number == 0:
             num_str = "0"
         else:
             num_str = str(number).replace("j", "i")
         num = TexMobject(num_str)
         num.scale(self.number_scale_factor)
         num.shift(point-num.get_corner(UP+LEFT)+nudge)
         result.append(num)
     return result
Пример #50
0
def get_top_inverse_rules():
    result = []
    pairs = [#Careful of order here!
        (0, 2),
        (0, 1),
        (1, 0),
        (1, 2),
        (2, 0),
        (2, 1),
    ]
    for i, j in pairs:
        top = get_top_inverse(i, j)
        char = ["x", "y", "z"][j]
        eq = TexMobject("= %s"%char)
        eq.scale(2)
        eq.next_to(top, RIGHT)
        diff = eq.get_center() - top.triangle.get_center()
        eq.shift(diff[1]*UP)
        result.append(VMobject(top, eq))
    return result
Пример #51
0
    def ask_continuous_question(self):
        continuous = self.get_continuous_background()
        line = Line(
            UP, DOWN,
            density = self.zoom_factor*DEFAULT_POINT_DENSITY_1D
        )
        theta = TexMobject("\\theta")
        theta.scale(0.5/self.zoom_factor)

        self.play(
            ShowCreation(continuous),
            Animation(self.equation)
        )
        self.remove(*self.layers)
        self.play(ShowCreation(self.cycloid))
        self.activate_zooming()
        little_square = self.get_zoomed_camera_mobject()

        self.add(line)
        indices = np.arange(
            0, self.cycloid.get_num_points()-1, 10
        )
        for index in indices:
            point = self.cycloid.points[index]
            next_point = self.cycloid.points[index+1]
            angle = angle_of_vector(point - next_point)
            for mob in little_square, line:
                mob.shift(point - mob.get_center())
            arc = Arc(angle-np.pi/2, start_angle = np.pi/2)
            arc.scale(0.1)
            arc.shift(point)
            self.add(arc)
            if angle > np.pi/2 + np.pi/6:
                vect_angle = interpolate(np.pi/2, angle, 0.5)
                vect = rotate_vector(RIGHT, vect_angle)
                theta.center()
                theta.shift(point)
                theta.shift(0.15*vect)
                self.add(theta)
            self.dither(self.frame_duration)
            self.remove(arc)
Пример #52
0
 def get_marks(self, point1, point2):
     vert_line = Line(2*DOWN, 2*UP)
     tangent_line = vert_line.copy()
     theta = TexMobject("\\theta")
     theta.scale(0.5)
     angle = angle_of_vector(point1 - point2)
     tangent_line.rotate(
         angle - tangent_line.get_angle()
     )
     angle_from_vert = angle - np.pi/2
     for mob in vert_line, tangent_line:
         mob.shift(point1 - mob.get_center())
     arc = Arc(angle_from_vert, start_angle = np.pi/2)
     arc.scale(self.arc_radius)
     arc.shift(point1)
     vect_angle = angle_from_vert/2 + np.pi/2
     vect = rotate_vector(RIGHT, vect_angle)
     theta.center()
     theta.shift(point1)
     theta.shift(1.5*self.arc_radius*vect)
     return arc, theta, vert_line, tangent_line
Пример #53
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.dither(2)
Пример #54
0
    def show_angles(self, ring):
        ring_center = ring.get_center()
        lines, arcs, thetas = [], [], []
        counter = it.count(1)
        for point in self.start_point, self.end_point:
            line = Line(point, ring_center, color = GREY)
            angle = np.pi/2-np.abs(np.arctan(line.get_slope()))
            arc = Arc(angle, radius = 0.5).rotate(np.pi/2)
            if point is self.end_point:
                arc.rotate(np.pi)
            theta = TexMobject("\\theta_%d"%counter.next())
            theta.scale(0.5)
            theta.shift(2*arc.get_center())
            arc.shift(ring_center)
            theta.shift(ring_center)

            lines.append(line)
            arcs.append(arc)
            thetas.append(theta)
        vert_line = Line(2*UP, 2*DOWN)
        vert_line.shift(ring_center)
        top_spring, bottom_spring = self.start_springs.split()

        self.play(
            Transform(ring, Point(ring_center)),
            Transform(top_spring, lines[0]),
            Transform(bottom_spring, lines[1])
        )
        self.play(ShowCreation(vert_line))
        anims = []
        for arc, theta in zip(arcs, thetas):
            anims += [
                ShowCreation(arc),
                GrowFromCenter(theta)
            ]
        self.play(*anims)
        self.dither()
Пример #55
0
    def construct(self):
        self.setup()
        symbols = TexMobject(list(self.symbols_str))
        symbols.scale(1.5)
        symbols.to_edge(UP)
        a, b, c = None, None, None
        for mob, letter in zip(symbols.split(), self.symbols_str):
            if letter == "A":
                a = mob
            elif letter == "B":
                b = mob
            elif letter == "C":
                c = mob

        symbols.add_background_rectangle()
        self.add_foreground_mobject(symbols)

        brace = Brace(c, DOWN)
        words = TextMobject("Apply this transformation")
        words.add_background_rectangle()
        words.next_to(brace, DOWN)
        brace.add(words)

        self.play(Write(brace, run_time = 1))
        self.add_foreground_mobject(brace)

        last = VectorizedPoint()
        for t_matrix, sym in zip(self.t_matrices, [c, b, a]):
            self.play(
                brace.next_to, sym, DOWN,
                sym.highlight, YELLOW,
                last.highlight, WHITE
            )
            self.apply_transposed_matrix(t_matrix, run_time = 1)
            last = sym
        self.dither()
Пример #56
0
 def get_line_brace_text(self, func_name = "sin"):
     line = self.get_trig_line(func_name)
     angle = line.get_angle()
     vect = rotate_vector(UP, angle)
     vect = np.round(vect, 1)
     if (vect[1] < 0) ^ (func_name is "sec"):
         vect = -vect
         angle += np.pi
     brace = Brace(
         Line(
             line.get_length()*LEFT/2,
             line.get_length()*RIGHT/2,
         ), 
         UP
     )
     brace.rotate(angle)
     brace.shift(line.get_center())
     brace.highlight(line.get_color())
     text = TexMobject("\\%s(\\theta)"%func_name)
     text.scale(0.75)
     text[-2].highlight(self.theta_color)
     text.add_background_rectangle()
     text.next_to(brace.get_center_of_mass(), vect, buff = 1.2*MED_SMALL_BUFF)
     return VGroup(line, brace, text)
Пример #57
0
    def write_function(self):
        brace = Brace(self.det_text, DOWN)
        number_text = brace.get_text("Number")
        self.play(Transform(self.title, self.title.not_real))
        self.dither()
        self.play(FadeOut(self.definitions))
        self.play(
            GrowFromCenter(brace),
            Write(number_text)
        )
        self.dither()

        x, y, z = variables = map(TexMobject, "xyz")
        for var, entry in zip(variables, self.u_entries):
            var.scale(0.8) 
            var.move_to(entry)
            entry.target = var
        brace.target = Brace(z)
        brace.target.stretch_to_fit_width(0.5)
        number_text.target = brace.target.get_text("Variable")
        v_brace = Brace(self.matrix.get_mob_matrix()[0, 1], UP)
        w_brace = Brace(self.matrix.get_mob_matrix()[0, 2], UP)
        for vect_brace, tex in (v_brace, self.v_tex), (w_brace, self.w_tex):
            vect_brace.stretch_to_fit_width(brace.target.get_width())
            new_tex = tex.copy()
            vect_brace.put_at_tip(new_tex)
            vect_brace.tex = new_tex
        func_tex = TexMobject(
            "f\\left(%s\\right)"%matrix_to_tex_string(list("xyz"))
        )
        func_tex.scale(0.7)
        func_input = Matrix(list("xyz"))
        func_input_template = Group(*func_tex[3:-2])
        func_input.scale_to_fit_height(func_input_template.get_height())
        func_input.next_to(Group(*func_tex[:3]), RIGHT)
        Group(*func_tex[-2:]).next_to(func_input, RIGHT)
        func_tex[0].scale_in_place(1.5)

        func_tex = Group(
            Group(*[func_tex[i] for i in 0, 1, 2, -2, -1]),
            func_input
        )
        func_tex.next_to(self.equals, LEFT)

        self.play(
            FadeOut(self.title),
            FadeOut(self.triple_cross),
            *[
                Transform(mob, mob.target)
                for mob in [brace, number_text]
            ]
        )
        self.play(*[
            Transform(mob, mob.target)
            for mob in self.u_entries
        ])
        self.play(*[
            Write(Group(vect_brace, vect_brace.tex))
            for vect_brace in v_brace, w_brace
        ])
        self.dither()
        self.play(Write(func_tex))
        self.dither()

        self.func_tex = func_tex
        self.variables_text = Group(brace, number_text)
Пример #58
0
    def construct(self):
        top = TOP()
        times = top.put_in_vertex(0, TexMobject("\\times"))
        times.highlight(YELLOW)
        oplus = top.put_in_vertex(1, TexMobject("\\oplus"))
        oplus.highlight(BLUE)
        dot = top.put_in_vertex(2, Dot())
        eight = top.put_on_vertex(2, TexMobject("8"))

        self.add(top)
        self.play(ShowCreation(eight))
        for mob in dot, oplus, times:
            self.play(ShowCreation(mob))
            self.dither()

        top.add(eight)
        top.add(times, oplus, dot)
        top1, top2, top3 = tops = [
            top.copy() for i in range(3)
        ]
        big_oplus = TexMobject("\\oplus").scale(2).highlight(BLUE)
        equals = TexMobject("=")
        equation = VMobject(
            top1, big_oplus, top2, equals, top3
        )
        equation.arrange_submobjects()
        top3.shift(0.5*RIGHT)
        x, y, xy = [
            t.put_on_vertex(0, s)
            for t, s in zip(tops, ["x", "y", "xy"])
        ]
        old_style_eq = TexMobject(
            "\\dfrac{1}{\\frac{1}{\\log_x(8)} + \\frac{1}{\\log_y(8)}} = \\log_{xy}(8)"
        )
        old_style_eq.to_edge(UP).highlight(RED)

        triple_top_copy = VMobject(*[
            top.copy() for i in range(3)
        ])
        self.clear()
        self.play(
            Transform(triple_top_copy, VMobject(*tops)),
            FadeIn(VMobject(x, y, xy, big_oplus, equals))
        )
        self.remove(triple_top_copy)
        self.add(*tops)
        self.play(Write(old_style_eq))
        self.dither(3)

        syms = VMobject(x, y, xy)
        new_syms = VMobject(*[
            t.put_on_vertex(1, s)
            for t, s in zip(tops, ["x", "y", "x \\oplus y"])
        ])
        new_old_style_eq = TexMobject(
            "\\sqrt[x]{8} \\sqrt[y]{8} = \\sqrt[X]{8}"
        )
        X = new_old_style_eq.split()[-4]
        frac = TexMobject("\\frac{1}{\\frac{1}{x} + \\frac{1}{y}}")
        frac.replace(X)
        frac_lower_right = frac.get_corner(DOWN+RIGHT)
        frac.scale(2)
        frac.shift(frac_lower_right - frac.get_corner(DOWN+RIGHT))
        new_old_style_eq.submobjects[-4] = frac
        new_old_style_eq.to_edge(UP)
        new_old_style_eq.highlight(RED)
        big_times = TexMobject("\\times").highlight(YELLOW)
        big_times.shift(big_oplus.get_center())
        self.play(
            Transform(old_style_eq, new_old_style_eq),
            Transform(syms, new_syms, path_arc = np.pi/2),
            Transform(big_oplus, big_times)
        )
        self.dither(4)