示例#1
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
示例#2
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
示例#3
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
示例#4
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()
示例#5
0
    def construct(self):
        top1, top2, top3 = old_tops = [
            TOP(None, s, "8")
            for s in "x", "y", TexMobject("x?y")
        ]
        q_mark = TexMobject("?").scale(2)
        equation = VMobject(
            top1, q_mark, top2, TexMobject("="), top3
        )
        equation.arrange_submobjects(buff = 0.7)
        symbols_at_top = VMobject(*[
            top.values[1]
            for top in top1, top2, top3
        ])
        symbols_at_lower_right = VMobject(*[
            top.put_on_vertex(0, top.values[1].copy())
            for top in top1, top2, top3
        ])
        old_style_eq1 = TexMobject("\\sqrt[x]{8} ? \\sqrt[y]{8} = \\sqrt[x?y]{8}")
        old_style_eq1.highlight(BLUE)
        old_style_eq2 = TexMobject("\\log_x(8) ? \\log_y(8) = \\log_{x?y}(8)")
        old_style_eq2.highlight(YELLOW)
        for eq in old_style_eq1, old_style_eq2:
            eq.to_edge(UP)

        randy = Randolph()
        randy.to_corner()
        bubble = ThoughtBubble().pin_to(randy)
        bubble.add_content(TOP(None, None, "8"))

        self.add(randy, bubble)
        self.play(ApplyMethod(randy.change_mode, "pondering"))
        self.dither(3)
        triangle = bubble.content.triangle
        eight = bubble.content.values[2]
        bubble.clear()
        self.play(
            Transform(triangle, equation),
            FadeOut(eight),
            ApplyPointwiseFunction(
                lambda p : (p+2*DOWN)*15/np.linalg.norm(p+2*DOWN),
                bubble
            ),
            FadeIn(old_style_eq1),
            ApplyMethod(randy.shift, 3*DOWN + 3*LEFT),
            run_time = 2
        )
        self.remove(triangle)
        self.add(equation)
        self.dither(4)
        self.play(
            Transform(
                symbols_at_top, symbols_at_lower_right, 
                path_arc = np.pi/2
            ),
            Transform(old_style_eq1, old_style_eq2)
        )
        self.dither(2)
示例#6
0
    def construct(self):
        v = TexMobject(self.v_str)
        v.highlight(YELLOW)
        eq = TexMobject("=")
        coords = Matrix(["x", "y", "z"])
        eq2 = eq.copy()
        if self.post_transform:
            L, l_paren, r_paren = map(TexMobject, "L()")
            parens = VMobject(l_paren, r_paren)
            parens.scale(2)
            parens.stretch_to_fit_height(
                coords.get_height()
            )
            VMobject(L, l_paren, coords, r_paren).arrange_submobjects(buff = 0.1)
            coords.submobjects = [L, l_paren] + coords.submobjects + [r_paren]

        lin_comb = VMobject(*map(TexMobject, [
            "x", self.i_str, "+",
            "y", self.j_str, "+",
            "z", self.k_str,
        ]))
        lin_comb.arrange_submobjects(
            RIGHT, buff = 0.1, 
            aligned_edge = ORIGIN if self.post_transform else DOWN
        )
        lin_comb_parts = np.array(lin_comb.split())
        new_x, new_y, new_z = lin_comb_parts[[0, 3, 6]]
        i, j, k = lin_comb_parts[[1, 4, 7]]
        plusses = lin_comb_parts[[2, 5]]
        i.highlight(X_COLOR)
        j.highlight(Y_COLOR)
        k.highlight(Z_COLOR)

        everything = VMobject(v, eq, coords, eq2, lin_comb)
        everything.arrange_submobjects(buff = 0.2)
        everything.scale_to_fit_width(2*SPACE_WIDTH - 1)
        everything.to_edge(DOWN)
        if not self.post_transform:
            lin_comb.shift(0.35*UP)

        self.play(*map(Write, [v, eq, coords]))
        self.dither()
        self.play(
            Transform(
                coords.get_entries().copy(),
                VMobject(new_x, new_y, new_z),
                path_arc = -np.pi,
                submobject_mode = "lagged_start"
            ),
            Write(VMobject(*[eq2, i, j, k] + list(plusses))),
            run_time = 3
        )
        self.dither()
示例#7
0
 def get_theta_group(self):
     arc = Arc(
         self.theta_value, 
         radius = self.arc_radius,
         color = self.theta_color,
     )
     theta = TexMobject("\\theta")
     theta.shift(1.5*arc.point_from_proportion(0.5))
     theta.highlight(self.theta_color)
     theta.scale_to_fit_height(self.theta_height)
     line = Line(ORIGIN, self.get_circle_point())
     dot = Dot(line.get_end(), radius = 0.05)
     return VGroup(line, arc, theta, dot)
示例#8
0
    def construct(self):
        v_mob = TexMobject(get_vect_tex("v"))
        v_mob.highlight(V_COLOR)

        matrix = Matrix([self.vect_coords])
        vector = Matrix(self.vect_coords)
        matrix.highlight_columns(X_COLOR, Y_COLOR)
        vector.highlight_columns(YELLOW)
        _input = Matrix(["x", "y"])
        _input.get_entries().gradient_highlight(X_COLOR, Y_COLOR)
        left_input, right_input = [_input.copy() for x in range(2)]
        dot, equals = map(TexMobject, ["\\cdot", "="])
        equation = Group(
            vector, dot, left_input, equals,
            matrix, right_input
        )
        equation.arrange_submobjects()
        left_brace = Brace(Group(vector, left_input))
        right_brace = Brace(matrix, UP)
        left_words = left_brace.get_text("Dot product")
        right_words = right_brace.get_text("Transform")
        right_words.scale_to_fit_width(right_brace.get_width())

        right_v_brace = Brace(right_input, UP)
        right_v_mob = v_mob.copy()
        right_v_brace.put_at_tip(right_v_mob)
        right_input.add(right_v_brace, right_v_mob)
        left_v_brace = Brace(left_input, UP)
        left_v_mob = v_mob.copy()
        left_v_brace.put_at_tip(left_v_mob)
        left_input.add(left_v_brace, left_v_mob)        


        self.add(matrix, right_input)
        self.play(
            GrowFromCenter(right_brace),
            Write(right_words, run_time = 1)
        )
        self.dither()
        self.play(
            Write(equals),
            Write(dot),
            Transform(matrix.copy(), vector),
            Transform(right_input.copy(), left_input)
        )
        self.play(
            GrowFromCenter(left_brace),
            Write(left_words, run_time = 1)
        )
        self.dither()
示例#9
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
示例#10
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
示例#11
0
文件: chapter1.py 项目: namkam5/manim
    def construct(self):
        v = TexMobject("\\vec{\\textbf{v}}")
        v.highlight(YELLOW)
        nums = map(TexMobject, ["2", "\\dfrac{1}{3}", "-1.8"])
        for mob in [v] + nums:
            mob.scale(1.5)

        self.play(Write(v, run_time = 1))
        last = None
        for num in nums:
            num.next_to(v, LEFT)
            if last:
                self.play(Transform(last, num))
            else:
                self.play(FadeIn(num))
                last = num
            self.dither()
示例#12
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.dither()
        self.play(
            Write(words),
            ShowCreation(
                arrows[0], 
                rate_func = squish_rate_func(smooth, 0.5, 1)
            ),
            run_time = 2
        )
        self.animate_secant_slope_group_change(
            self.ss_group, target_x = self.x3,
            run_time = 3,
            added_anims = [
                Transform(
                    *arrows, 
                    run_time = 3,
                    path_arc = 0.75*np.pi
                ),
            ]
        )
        self.play(FadeOut(arrows[0]))
        self.animate_secant_slope_group_change(
            self.ss_group, target_x = self.x2,
            run_time = 3,
        )

        self.second_deriv_words = words
        self.second_deriv = second_deriv
示例#13
0
 def label_graph(self, graph, label = "f(x)", 
                 proportion = 0.7, 
                 direction = LEFT,
                 buff = 2*MED_BUFF,
                 animate = True
                 ):
     label = TexMobject(label)
     label.highlight(graph.get_color())
     label.next_to(
         graph.point_from_proportion(proportion), 
         direction,
         buff = buff
     )
     if animate:
         self.play(Write(label))
     self.add(label)
     return label
示例#14
0
文件: chapter5.py 项目: xhrwang/manim
    def construct(self):
        self.setup()
        self.add_unit_square()
        a, b, c, d = 3, 2, 3.5, 2

        self.dither()
        self.apply_transposed_matrix([[a, 0], [0, 1]])
        i_brace = Brace(self.i_hat, DOWN)
        width = TexMobject("a").scale(1.5)
        i_brace.put_at_tip(width)
        width.highlight(X_COLOR)
        width.add_background_rectangle()
        self.play(GrowFromCenter(i_brace), Write(width))
        self.dither()

        self.apply_transposed_matrix([[1, 0], [0, d]])
        side_brace = Brace(self.square, RIGHT)
        height = TexMobject("d").scale(1.5)
        side_brace.put_at_tip(height)
        height.highlight(Y_COLOR)
        height.add_background_rectangle()
        self.play(GrowFromCenter(side_brace), Write(height))
        self.dither()

        self.apply_transposed_matrix(
            [[1, 0], [float(b)/d, 1]],
            added_anims = [
                ApplyMethod(m.shift, b*RIGHT)
                for m in side_brace, height
            ]
        )
        self.dither()
        self.play(*map(FadeOut, [i_brace, side_brace, width, height]))
        matrix1 = np.dot(
            [[a, b], [c, d]],
            np.linalg.inv([[a, b], [0, d]])
        )
        matrix2 = np.dot(
            [[a, b], [-c, d]],
            np.linalg.inv([[a, b], [c, d]])
        )
        self.apply_transposed_matrix(matrix1.transpose(), path_arc = 0)
        self.dither()
        self.apply_transposed_matrix(matrix2.transpose(), path_arc = 0)
        self.dither()
示例#15
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)
示例#16
0
文件: patreon.py 项目: aquafemi/manim
    def full_time(self, morty):
        new_title = TextMobject("Full time")
        new_title.move_to(self.screen_title)
        q_mark = TexMobject("?")
        q_mark.next_to(self.cross)
        q_mark.highlight(GREEN)

        self.play(morty.look_at, q_mark)
        self.play(Transform(self.screen_title, new_title))
        self.play(
            Transform(self.cross, q_mark),
            morty.change_mode, "confused"
        )
        self.play(Blink(morty))
        self.dither()
        self.play(
            morty.change_mode, "happy",
            morty.look, UP+RIGHT
        )
        self.play(Blink(morty))
        self.dither()
示例#17
0
文件: end.py 项目: PythonJedi/manim
    def construct(self):
        assyms_of_top = VMobject(
            TextMobject("Asymmetries of "),
            TOP("a", "b", "c", radius = 0.75).highlight(BLUE)
        ).arrange_submobjects()
        assyms_of_top.to_edge(UP)
        assyms_of_math = TextMobject("""
            Asymmetries of 
            $\\underbrace{a \\cdot a \\cdots a}_{\\text{$b$ times}} = c$
        """)
        VMobject(*assyms_of_math.split()[13:]).highlight(YELLOW)
        assyms_of_math.next_to(assyms_of_top, DOWN, buff = 2)
        rad = TexMobject("\\sqrt{\\quad}").to_edge(LEFT).shift(UP)
        rad.highlight(RED)
        log = TexMobject("\\log").next_to(rad, DOWN)
        log.highlight(RED)

        self.play(FadeIn(assyms_of_top))
        self.dither()
        self.play(FadeIn(assyms_of_math))
        self.dither()
        self.play(Write(VMobject(rad, log)))
        self.dither()
示例#18
0
    def construct(self):
        self.setup()
        self.add_unit_square()
        a, b, c, d = 3, 2, 3.5, 2

        self.dither()
        self.apply_transposed_matrix([[a, 0], [0, 1]])
        i_brace = Brace(self.i_hat, DOWN)
        width = TexMobject("a").scale(1.5)
        i_brace.put_at_tip(width)
        width.highlight(X_COLOR)
        width.add_background_rectangle()
        self.play(GrowFromCenter(i_brace), Write(width))
        self.dither()

        self.apply_transposed_matrix([[1, 0], [0, d]])
        side_brace = Brace(self.square, RIGHT)
        height = TexMobject("d").scale(1.5)
        side_brace.put_at_tip(height)
        height.highlight(Y_COLOR)
        height.add_background_rectangle()
        self.play(GrowFromCenter(side_brace), Write(height))
        self.dither()

        self.apply_transposed_matrix([[1, 0], [float(b) / d, 1]],
                                     added_anims=[
                                         ApplyMethod(m.shift, b * RIGHT)
                                         for m in side_brace, height
                                     ])
        self.dither()
        self.play(*map(FadeOut, [i_brace, side_brace, width, height]))
        matrix1 = np.dot([[a, b], [c, d]], np.linalg.inv([[a, b], [0, d]]))
        matrix2 = np.dot([[a, b], [-c, d]], np.linalg.inv([[a, b], [c, d]]))
        self.apply_transposed_matrix(matrix1.transpose(), path_arc=0)
        self.dither()
        self.apply_transposed_matrix(matrix2.transpose(), path_arc=0)
        self.dither()
示例#19
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.wait(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.wait(2)
示例#20
0
    def construct(self):
        top1 = get_const_top_TOP("x", "3")
        top2 = get_const_top_TOP("y", "3")
        top3 = get_const_top_TOP("xy", "3")
        times = TexMobject("\\times")
        equals = TexMobject("=")
        top_exp_equation = VMobject(
            top1, times, top2, equals, top3
        )
        top_exp_equation.arrange_submobjects()
        old_style_exp = TexMobject("(x^3)(y^3) = (xy)^3")
        old_style_exp.to_edge(UP)
        old_style_exp.highlight(GREEN)
        old_style_rad = TexMobject("\\sqrt[3]{x} \\sqrt[3]{y} = \\sqrt[3]{xy}")
        old_style_rad.to_edge(UP)
        old_style_rad.highlight(RED)

        self.add(top_exp_equation, old_style_exp)
        self.dither(3)

        old_tops = [top1, top2, top3]
        new_tops = []
        for top in old_tops:
            new_top = top.copy()
            new_top.put_on_vertex(2, new_top.values[0])
            new_top.shift(0.5*LEFT)
            new_tops.append(new_top)
        self.play(
            Transform(old_style_exp, old_style_rad),
            Transform(
                VMobject(*old_tops),
                VMobject(*new_tops),
                path_arc = np.pi/2
            )
        )
        self.dither(3)
示例#21
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
示例#22
0
    def construct(self):
        top1 = get_const_top_TOP("x", "3")
        top2 = get_const_top_TOP("y", "3")
        top3 = get_const_top_TOP("xy", "3")
        times = TexMobject("\\times")
        equals = TexMobject("=")
        top_exp_equation = VMobject(
            top1, times, top2, equals, top3
        )
        top_exp_equation.arrange_submobjects()
        old_style_exp = TexMobject("(x^3)(y^3) = (xy)^3")
        old_style_exp.to_edge(UP)
        old_style_exp.highlight(GREEN)
        old_style_rad = TexMobject("\\sqrt[3]{x} \\sqrt[3]{y} = \\sqrt[3]{xy}")
        old_style_rad.to_edge(UP)
        old_style_rad.highlight(RED)

        self.add(top_exp_equation, old_style_exp)
        self.wait(3)

        old_tops = [top1, top2, top3]
        new_tops = []
        for top in old_tops:
            new_top = top.copy()
            new_top.put_on_vertex(2, new_top.values[0])
            new_top.shift(0.5*LEFT)
            new_tops.append(new_top)
        self.play(
            Transform(old_style_exp, old_style_rad),
            Transform(
                VMobject(*old_tops),
                VMobject(*new_tops),
                path_arc = np.pi/2
            )
        )
        self.wait(3)
示例#23
0
    def construct(self):
        num = TexMobject("2^{256}")
        num.scale_to_fit_height(2)
        num.highlight(BLUE_C)
        num.set_stroke(BLUE_B, 3)
        num.shift(MED_SMALL_BUFF * UP)
        num.add_background_rectangle(opacity=1)
        num.background_rectangle.scale_in_place(1.5)
        self.add(num)

        background_num_str = "115792089237316195423570985008687907853269984665640564039457584007913129639936"
        n_chars = len(background_num_str)
        new_str = ""
        for i, char in enumerate(background_num_str):
            new_str += char
            # if i%3 == 1:
            #     new_str += "{,}"
            if i % (n_chars / 4) == 0:
                new_str += " \\\\ "
        background_num = TexMobject(new_str)
        background_num.scale_to_fit_width(2 * SPACE_WIDTH - LARGE_BUFF)
        background_num.set_fill(opacity=0.2)

        secure = TextMobject("Secure?")
        secure.scale(4)
        secure.shift(SPACE_HEIGHT * DOWN / 2)
        secure.highlight(RED)
        secure.set_stroke(RED_A, 3)

        lock = SVGMobject(
            file_name="shield_locked",
            fill_color=WHITE,
        )
        lock.scale_to_fit_height(6)

        self.add(background_num, num)
示例#24
0
    def construct(self):
        v_mob = TexMobject(get_vect_tex("v"))
        v_mob.highlight(V_COLOR)

        matrix = Matrix([self.vect_coords])
        vector = Matrix(self.vect_coords)
        matrix.highlight_columns(X_COLOR, Y_COLOR)
        vector.highlight_columns(YELLOW)
        _input = Matrix(["x", "y"])
        _input.get_entries().gradient_highlight(X_COLOR, Y_COLOR)
        left_input, right_input = [_input.copy() for x in range(2)]
        dot, equals = map(TexMobject, ["\\cdot", "="])
        equation = VGroup(vector, dot, left_input, equals, matrix, right_input)
        equation.arrange_submobjects()
        left_brace = Brace(VGroup(vector, left_input))
        right_brace = Brace(matrix, UP)
        left_words = left_brace.get_text("Dot product")
        right_words = right_brace.get_text("Transform")
        right_words.scale_to_fit_width(right_brace.get_width())

        right_v_brace = Brace(right_input, UP)
        right_v_mob = v_mob.copy()
        right_v_brace.put_at_tip(right_v_mob)
        right_input.add(right_v_brace, right_v_mob)
        left_v_brace = Brace(left_input, UP)
        left_v_mob = v_mob.copy()
        left_v_brace.put_at_tip(left_v_mob)
        left_input.add(left_v_brace, left_v_mob)

        self.add(matrix, right_input)
        self.play(GrowFromCenter(right_brace), Write(right_words, run_time=1))
        self.dither()
        self.play(Write(equals), Write(dot), Transform(matrix.copy(), vector),
                  Transform(right_input.copy(), left_input))
        self.play(GrowFromCenter(left_brace), Write(left_words, run_time=1))
        self.dither()
示例#25
0
    def velocity_vector(self, parabola):
        alpha = 0.7
        d_alpha = 0.01
        vector_length = 3

        p1 = parabola.point_from_proportion(alpha)
        p2 = parabola.point_from_proportion(alpha + d_alpha)
        vector = vector_length*(p2-p1)/np.linalg.norm(p2-p1)
        v_mob = Vector(vector, color = YELLOW)
        vx = Vector(vector[0]*RIGHT, color = GREEN_B)
        vy = Vector(vector[1]*UP, color = RED)
        v_mob.shift(p1)
        vx.shift(p1)
        vy.shift(vx.get_end())

        arc = Arc(
            angle_of_vector(vector), 
            radius = vector_length / 4.
        )
        arc.shift(p1)
        theta = TexMobject("\\theta").scale(0.75)
        theta.next_to(arc, RIGHT, buff = 0.1)

        v_label = TexMobject("\\vec{v}")
        v_label.shift(p1 + RIGHT*vector[0]/4 + UP*vector[1]/2)
        v_label.highlight(v_mob.get_color())
        vx_label = TexMobject("||\\vec{v}|| \\cos(\\theta)")
        vx_label.next_to(vx, UP)
        vx_label.highlight(vx.get_color())
        vy_label = TexMobject("||\\vec{v}|| \\sin(\\theta)")
        vy_label.next_to(vy, RIGHT)
        vy_label.highlight(vy.get_color())

        kwargs = {"submobject_mode" : "one_at_a_time"}
        for v in v_mob, vx, vy:
            self.play(
                ShowCreation(v, submobject_mode = "one_at_a_time")
            )
        self.play(
            ShowCreation(arc),
            Write(theta, run_time = 1)
        )
        for label in v_label, vx_label, vy_label:
            self.play(Write(label, run_time = 1))
        self.dither()
示例#26
0
    def velocity_vector(self, parabola):
        alpha = 0.7
        d_alpha = 0.01
        vector_length = 3

        p1 = parabola.point_from_proportion(alpha)
        p2 = parabola.point_from_proportion(alpha + d_alpha)
        vector = vector_length * (p2 - p1) / np.linalg.norm(p2 - p1)
        v_mob = Vector(vector, color=YELLOW)
        vx = Vector(vector[0] * RIGHT, color=GREEN_B)
        vy = Vector(vector[1] * UP, color=RED)
        v_mob.shift(p1)
        vx.shift(p1)
        vy.shift(vx.get_end())

        arc = Arc(angle_of_vector(vector), radius=vector_length / 4.)
        arc.shift(p1)
        theta = TexMobject("\\theta").scale(0.75)
        theta.next_to(arc, RIGHT, buff=0.1)

        v_label = TexMobject("\\vec{v}")
        v_label.shift(p1 + RIGHT * vector[0] / 4 + UP * vector[1] / 2)
        v_label.highlight(v_mob.get_color())
        vx_label = TexMobject("||\\vec{v}|| \\cos(\\theta)")
        vx_label.next_to(vx, UP)
        vx_label.highlight(vx.get_color())
        vy_label = TexMobject("||\\vec{v}|| \\sin(\\theta)")
        vy_label.next_to(vy, RIGHT)
        vy_label.highlight(vy.get_color())

        kwargs = {"submobject_mode": "one_at_a_time"}
        for v in v_mob, vx, vy:
            self.play(ShowCreation(v, submobject_mode="one_at_a_time"))
        self.play(ShowCreation(arc), Write(theta, run_time=1))
        for label in v_label, vx_label, vy_label:
            self.play(Write(label, run_time=1))
        self.wait()
示例#27
0
    def construct(self):
        title = TextMobject("Putnam Competition")
        title.to_edge(UP, buff = MED_SMALL_BUFF)
        title.highlight(BLUE)
        six_hours = TextMobject("6", "hours")
        three_hours = TextMobject("3", "hours")
        for mob in six_hours, three_hours:
            mob.next_to(title, DOWN, MED_LARGE_BUFF)
            # mob.highlight(BLUE)
        three_hours.shift(SPACE_WIDTH*LEFT/2)
        three_hours_copy = three_hours.copy()
        three_hours_copy.shift(SPACE_WIDTH*RIGHT)

        question_groups = VGroup(*[
            VGroup(*[
                TextMobject("%s%d)"%(c, i))
                for i in range(1, 7)
            ]).arrange_submobjects(DOWN, buff = MED_LARGE_BUFF)
            for c in "A", "B"
        ]).arrange_submobjects(RIGHT, buff = SPACE_WIDTH - MED_SMALL_BUFF)
        question_groups.to_edge(LEFT)
        question_groups.to_edge(DOWN, MED_LARGE_BUFF)
        flat_questions = VGroup(*it.chain(*question_groups))

        rects = VGroup()
        for questions in question_groups:
            rect = SurroundingRectangle(questions, buff = MED_SMALL_BUFF)
            rect.set_stroke(WHITE, 2)
            rect.stretch_to_fit_width(SPACE_WIDTH - 1)
            rect.move_to(questions.get_left() + MED_SMALL_BUFF*LEFT, LEFT)
            rects.add(rect)

        out_of_tens = VGroup()
        for question in flat_questions:
            out_of_ten = TexMobject("/10")
            out_of_ten.highlight(GREEN)
            out_of_ten.move_to(question)
            dist = rects[0].get_width() - 1.2
            out_of_ten.shift(dist*RIGHT)
            out_of_tens.add(out_of_ten)

        out_of_120 = TexMobject("/120")
        out_of_120.next_to(title, RIGHT, LARGE_BUFF)
        out_of_120.highlight(GREEN)

        out_of_120.generate_target()
        out_of_120.target.to_edge(RIGHT, LARGE_BUFF)
        median = TexMobject("2")
        median.next_to(out_of_120.target, LEFT, SMALL_BUFF)
        median.highlight(RED)
        median.align_to(out_of_120[-1])
        median_words = TextMobject("Typical median $\\rightarrow$")
        median_words.next_to(median, LEFT)

        difficulty_strings = [
            "Pretty hard",
            "Hard",
            "Harder",
            "Very hard",
            "Ughhh",
            "Can I go home?"
        ]
        colors = color_gradient([YELLOW, RED], len(difficulty_strings))
        difficulties = VGroup()
        for i, s, color in zip(it.count(), difficulty_strings, colors):
            for question_group in question_groups:
                question = question_group[i]
                text = TextMobject("\\dots %s \\dots"%s)
                text.scale(0.7)
                text.next_to(question, RIGHT)
                text.highlight(color)
                difficulties.add(text)


        if self.dont_animate:        
            test = VGroup()
            test.rect = rects[0]
            test.questions = question_groups[0]
            test.out_of_tens = VGroup(*out_of_tens[:6])
            test.difficulties = VGroup(*difficulties[::2])
            test.digest_mobject_attrs()
            self.test = test
            return

        self.add(title)
        self.play(Write(six_hours))
        self.play(LaggedStart(
            GrowFromCenter, flat_questions,
            run_time = 3,
        ))
        self.play(
            ReplacementTransform(six_hours, three_hours),
            ReplacementTransform(six_hours.copy(), three_hours_copy),
            *map(ShowCreation, rects)
        )
        self.dither()
        self.play(LaggedStart(
            DrawBorderThenFill, out_of_tens,
            run_time = 3,
            stroke_color = YELLOW
        ))
        self.dither()
        self.play(ReplacementTransform(
            out_of_tens.copy(), VGroup(out_of_120),
            submobject_mode = "lagged_start",
            run_time = 2,
        ))
        self.dither()
        self.play(
            title.next_to, median_words.copy(), LEFT, LARGE_BUFF,
            MoveToTarget(out_of_120),
            Write(median_words)
        )
        self.play(Write(median))
        self.play(Write(difficulties, run_time = 3))
        self.dither()
示例#28
0
    def construct(self):
        scale_factor = 0.7
        sick = "\\text{sick}"
        positive = "\\text{positive}"
        formula = TexMobject("P(", sick, "\\,|\\,", positive, ")", "=",
                             "{\\quad P(", sick, "\\text{ and }", positive,
                             ") \\quad", "\\over", "P(", positive, ")}", "=",
                             "{1/1{,}000", "\\over", "1/1{,}000", "+",
                             "(999/1{,}000)(0.01)}")
        formula.scale(scale_factor)
        formula.next_to(self.pi_creatures, UP, LARGE_BUFF)
        formula.shift_onto_screen(buff=MED_LARGE_BUFF)
        equals_group = formula.get_parts_by_tex("=")
        equals_indices = [
            formula.index_of_part(equals) for equals in equals_group
        ]

        lhs = VGroup(*formula[:equals_indices[0]])
        initial_formula = VGroup(*formula[:equals_indices[1]])
        initial_formula.save_state()
        initial_formula.shift(3 * RIGHT)

        over = formula.get_part_by_tex("\\over")
        num_start_index = equals_indices[0] + 1
        num_end_index = formula.index_of_part(over)
        numerator = VGroup(*formula[num_start_index:num_end_index])
        numerator_rect = SurroundingRectangle(numerator)

        alt_numerator = TexMobject("P(", sick, ")", "P(", positive, "\\,|\\,",
                                   sick, ")")
        alt_numerator.scale(scale_factor)
        alt_numerator.move_to(numerator)

        number_fraction = VGroup(*formula[equals_indices[-1]:])

        rhs = TexMobject("\\approx 0.09")
        rhs.scale(scale_factor)
        rhs.move_to(equals_group[-1], LEFT)
        rhs.highlight(YELLOW)

        for mob in formula, alt_numerator:
            mob.highlight_by_tex(sick, SICKLY_GREEN)
            mob.highlight_by_tex(positive, YELLOW)

        #Ask question
        self.student_says("What does the \\\\ formula look like here?")
        self.play(self.teacher.change, "happy")
        self.dither()
        self.play(
            Write(lhs),
            RemovePiCreatureBubble(
                self.students[1],
                target_mode="pondering",
            ),
            self.teacher.change,
            "raise_right_hand",
            self.students[0].change,
            "pondering",
            self.students[2].change,
            "pondering",
        )
        self.dither()

        #Show initial formula
        lhs_copy = lhs.copy()
        self.play(
            LaggedStart(FadeIn, initial_formula, lag_ratio=0.7),
            Animation(lhs_copy, remover=True),
        )
        self.dither(2)
        self.play(ShowCreation(numerator_rect))
        self.play(FadeOut(numerator_rect))
        self.dither()
        self.play(Transform(numerator, alt_numerator))
        initial_formula.add(*numerator)
        formula.add(*numerator)
        self.dither(3)

        #Show number_fraction
        self.play(initial_formula.move_to, initial_formula.saved_state,
                  FadeIn(VGroup(*number_fraction[:3])))
        self.dither(2)
        self.play(
            LaggedStart(FadeIn,
                        VGroup(*number_fraction[3:]),
                        run_time=3,
                        lag_ratio=0.7))
        self.dither(2)

        #Show rhs
        self.play(formula.shift, UP)
        self.play(Write(rhs))
        self.change_student_modes(*["happy"] * 3)
        self.look_at(rhs)
        self.dither(2)
示例#29
0
    def construct(self):
        clunky_deriv = TexMobject(
            "{d", "\\big(", "{df", "\\over", "dx}", "\\big)",
            "\\over", "dx }"
        )
        over_index = clunky_deriv.index_of_part(
            clunky_deriv.get_parts_by_tex("\\over")[1]
        )
        numerator = VGroup(*clunky_deriv[:over_index])
        denominator = VGroup(*clunky_deriv[over_index+1:])


        rp = clunky_deriv.get_part_by_tex("(")
        lp = clunky_deriv.get_part_by_tex(")")
        dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [
            "df", "over", "dx"
        ])
        df_over_dx = VGroup(dfs[0], overs[0], dxs[0])
        d = clunky_deriv.get_part_by_tex("d")
        d_over_dx = VGroup(d, overs[1], dxs[1])

        d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}")
        d2f_over_dx2.highlight_by_tex("dx", YELLOW)

        for mob in clunky_deriv, d2f_over_dx2:
            mob.next_to(self.teacher, UP+LEFT)

        for mob in numerator, denominator:
            circle = Circle(color = YELLOW)
            circle.replace(mob, stretch = True)
            circle.scale_in_place(1.3)
            mob.circle = circle
        dx_to_zero = TexMobject("dx \\to 0")
        dx_to_zero.highlight(YELLOW)
        dx_to_zero.next_to(clunky_deriv, UP+LEFT)

        self.student_says(
            "What's that notation?",
            target_mode = "raise_left_hand"
        )
        self.change_student_modes("confused", "raise_left_hand", "confused")
        self.play(
            FadeIn(
                clunky_deriv,
                run_time = 2,
                submobject_mode = "lagged_start"
            ),
            RemovePiCreatureBubble(self.get_students()[1]),
            self.teacher.change_mode, "raise_right_hand"
        )
        self.dither()
        self.play(ShowCreation(numerator.circle))
        self.dither()
        self.play(ReplacementTransform(
            numerator.circle,
            denominator.circle,
        ))
        self.dither()
        self.play(
            FadeOut(denominator.circle),
            Write(dx_to_zero),
            dxs.highlight, YELLOW
        )
        self.dither()
        self.play(
            FadeOut(dx_to_zero),
            *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()]
        )
        self.play(
            df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(),
            df_over_dx.move_to, d_over_dx, RIGHT,
            FadeOut(VGroup(lp, rp)),
            d_over_dx.shift, 0.8*LEFT + 0.05*UP,
        )
        self.dither()
        self.play(*[
            ReplacementTransform(
                group,
                VGroup(d2f_over_dx2.get_part_by_tex(tex))
            )
            for group, tex in [
                (VGroup(d, dfs[0]), "d^2"),
                (overs, "over"),
                (dxs, "dx"),
                (VGroup(dxs[1].copy()), "^2}"),
            ]
        ])
        self.dither(2)
        self.student_says(
            "How does one... \\\\ read that?",
            student_index = 0,
        )
        self.play(self.teacher.change, "happy")
        self.dither(2)
示例#30
0
    def introduce_dual_vector(self):
        everything = Group(*self.get_mobjects())
        colors = [X_COLOR, Y_COLOR, Z_COLOR]
        q_marks = Group(*map(TextMobject, "???"))
        q_marks.scale(2)
        q_marks.gradient_highlight(*colors)

        title = Group(TextMobject("This function is linear"))
        title.highlight(GREEN)
        title.to_edge(UP)
        matrix = Matrix([list(q_marks.copy())])
        matrix.scale_to_fit_height(self.func_tex.get_height()/2)
        dual_vector = Matrix(list(q_marks))
        dual_vector.scale_to_fit_height(self.func_tex.get_height())
        dual_vector.get_brackets()[0].shift(0.2*LEFT)
        dual_vector.get_entries().shift(0.1*LEFT)
        dual_vector.scale(1.25)
        dual_dot = Group(
            dual_vector,
            TexMobject("\\cdot").next_to(dual_vector)
        )
        matrix_words = TextMobject("""
            $1 \\times 3$ matrix encoding the 
            3d-to-1d linear transformation
        """)

        self.play(
            Write(title, run_time = 2),
            everything.shift, DOWN
        )
        self.remove(everything)
        self.add(*everything)
        self.dither()

        func, func_input = self.func_tex
        func_input.target = func_input.copy()
        func_input.target.scale(1.2)
        func_input.target.move_to(self.func_tex, aligned_edge = RIGHT)
        matrix.next_to(func_input.target, LEFT)
        dual_dot.next_to(func_input.target, LEFT)
        matrix_words.next_to(matrix, DOWN, buff = 1.5)
        matrix_words.shift_onto_screen()
        matrix_arrow = Arrow(
            matrix_words.get_top(),
            matrix.get_bottom(),
            color = WHITE
        )

        self.play(
            Transform(func, matrix),
            MoveToTarget(func_input),
            FadeOut(self.variables_text),
        )
        self.dither()
        self.play(
            Write(matrix_words),
            ShowCreation(matrix_arrow)
        )
        self.dither(2)
        self.play(*map(FadeOut, [matrix_words, matrix_arrow]))
        self.play(
            Transform(func, dual_vector),
            Write(dual_dot[1])
        )
        self.dither()

        p_coords = Group(*map(TexMobject, [
            "p_%d"%d for d in range(1, 4)
        ]))
        p_coords.highlight(RED)        
        p_array = Matrix(list(p_coords))
        p_array.scale_to_fit_height(dual_vector.get_height())
        p_array.move_to(dual_vector, aligned_edge = RIGHT)
        p_brace = Brace(p_array, UP)
        p_tex = TexMobject(get_vect_tex("p"))
        p_tex.highlight(P_COLOR)
        p_brace.put_at_tip(p_tex)

        self.play(
            GrowFromCenter(p_brace),
            Write(p_tex)
        )
        self.play(Transform(
            func, p_array,
            run_time = 2,
            submobject_mode = "lagged_start"
        ))
        self.remove(func)
        self.add(p_array)
        self.dither()
        self.play(FadeOut(title))
        self.dither()

        self.p_array = p_array
        self.input_array = func_input
示例#31
0
    def house_example(self, starter_mobject, title):
        house = SVGMobject("house")
        house.set_stroke(width=0)
        house.set_fill(BLUE_C, opacity=1)
        house.scale_to_fit_height(3)
        house.center()
        square_footage_words = TextMobject("Square footage:")
        price_words = TextMobject("Price: ")
        square_footage = TexMobject("2{,}600\\text{ ft}^2")
        price = TextMobject("\\$300{,}000")

        house.to_edge(LEFT).shift(UP)
        square_footage_words.next_to(house, RIGHT)
        square_footage_words.shift(0.5 * UP)
        square_footage_words.highlight(RED)
        price_words.next_to(square_footage_words, DOWN, aligned_edge=LEFT)
        price_words.highlight(GREEN)
        square_footage.next_to(square_footage_words)
        square_footage.highlight(RED)
        price.next_to(price_words)
        price.highlight(GREEN)

        vector = Matrix([square_footage.copy(), price.copy()])
        vector.next_to(house, RIGHT).shift(0.25 * UP)
        new_square_footage, new_price = vector.get_mob_matrix().flatten()
        not_equals = TexMobject("\\ne")
        not_equals.next_to(vector)
        alt_vector = Matrix([
            TextMobject("300{,}000\\text{ ft}^2").highlight(RED),
            TextMobject("\\$2{,}600").highlight(GREEN)
        ])
        alt_vector.next_to(not_equals)

        brace = Brace(vector, RIGHT)
        two_dimensional = TextMobject("2 dimensional")
        two_dimensional.next_to(brace)
        brackets = vector.get_brackets()

        self.play(Transform(starter_mobject, house))
        self.remove(starter_mobject)
        self.add(house)
        self.add(square_footage_words)
        self.play(Write(square_footage, run_time=2))
        self.add(price_words)
        self.play(Write(price, run_time=2))
        self.dither()
        self.play(FadeOut(square_footage_words),
                  FadeOut(price_words),
                  Transform(square_footage, new_square_footage),
                  Transform(price, new_price),
                  Write(brackets),
                  run_time=1)
        self.remove(square_footage_words, price_words)
        self.dither()
        self.play(Write(not_equals), Write(alt_vector), run_time=1)
        self.dither()
        self.play(FadeOut(not_equals), FadeOut(alt_vector))
        self.remove(not_equals, alt_vector)
        self.dither()
        self.play(GrowFromCenter(brace), Write(two_dimensional), run_time=1)
        self.dither()

        everything = VMobject(house, square_footage, price, brackets, brace,
                              two_dimensional, title)
        self.play(ApplyMethod(everything.shift, 2 * SPACE_WIDTH * LEFT))
        self.remove(everything)
示例#32
0
    def introduce_dual_vector(self):
        everything = VGroup(*self.get_mobjects())
        colors = [X_COLOR, Y_COLOR, Z_COLOR]
        q_marks = VGroup(*map(TextMobject, "???"))
        q_marks.scale(2)
        q_marks.gradient_highlight(*colors)

        title = VGroup(TextMobject("This function is linear"))
        title.highlight(GREEN)
        title.to_edge(UP)
        matrix = Matrix([list(q_marks.copy())])
        matrix.scale_to_fit_height(self.func_tex.get_height() / 2)
        dual_vector = Matrix(list(q_marks))
        dual_vector.scale_to_fit_height(self.func_tex.get_height())
        dual_vector.get_brackets()[0].shift(0.2 * LEFT)
        dual_vector.get_entries().shift(0.1 * LEFT)
        dual_vector.scale(1.25)
        dual_dot = VGroup(dual_vector,
                          TexMobject("\\cdot").next_to(dual_vector))
        matrix_words = TextMobject("""
            $1 \\times 3$ matrix encoding the 
            3d-to-1d linear transformation
        """)

        self.play(Write(title, run_time=2), everything.shift, DOWN)
        self.remove(everything)
        self.add(*everything)
        self.dither()

        func, func_input = self.func_tex
        func_input.target = func_input.copy()
        func_input.target.scale(1.2)
        func_input.target.move_to(self.func_tex, aligned_edge=RIGHT)
        matrix.next_to(func_input.target, LEFT)
        dual_dot.next_to(func_input.target, LEFT)
        matrix_words.next_to(matrix, DOWN, buff=1.5)
        matrix_words.shift_onto_screen()
        matrix_arrow = Arrow(matrix_words.get_top(),
                             matrix.get_bottom(),
                             color=WHITE)

        self.play(
            Transform(func, matrix),
            MoveToTarget(func_input),
            FadeOut(self.variables_text),
        )
        self.dither()
        self.play(Write(matrix_words), ShowCreation(matrix_arrow))
        self.dither(2)
        self.play(*map(FadeOut, [matrix_words, matrix_arrow]))
        self.play(Transform(func, dual_vector), Write(dual_dot[1]))
        self.dither()

        p_coords = VGroup(*map(TexMobject, ["p_%d" % d for d in range(1, 4)]))
        p_coords.highlight(RED)
        p_array = Matrix(list(p_coords))
        p_array.scale_to_fit_height(dual_vector.get_height())
        p_array.move_to(dual_vector, aligned_edge=RIGHT)
        p_brace = Brace(p_array, UP)
        p_tex = TexMobject(get_vect_tex("p"))
        p_tex.highlight(P_COLOR)
        p_brace.put_at_tip(p_tex)

        self.play(GrowFromCenter(p_brace), Write(p_tex))
        self.play(
            Transform(func,
                      p_array,
                      run_time=2,
                      submobject_mode="lagged_start"))
        self.remove(func)
        self.add(p_array)
        self.dither()
        self.play(FadeOut(title))
        self.dither()

        self.p_array = p_array
        self.input_array = func_input
示例#33
0
文件: wcat.py 项目: clust3r1/manim
    def construct(self):
        dots = VGroup(
            Dot(4*RIGHT+0.5*DOWN, color = MAROON_B),
            Dot(5*RIGHT+3*UP, color = MAROON_B),
            Dot(LEFT+0.1*DOWN, color = PURPLE_B),
            Dot(2*LEFT+UP, color = PURPLE_B)
        )
        labels = VGroup()
        for dot, char in zip(dots, "acbd"):
            label = TexMobject(char)
            y_coord = dot.get_center()[1]
            label.next_to(dot, np.sign(dot.get_center()[1])*UP)
            label.highlight(dot.get_color())
            labels.add(label)
        lines = [
            Line(
                dots[i].get_center(), 
                dots[j].get_center(), 
                color = dots[i].get_color()
            )
            for i, j in (0, 1), (2, 3)
        ]
        groups = [
            VGroup(dots[0], dots[1], labels[0], labels[1], lines[0]),
            VGroup(dots[2], dots[3], labels[2], labels[3], lines[1]),
        ]
        midpoint = Dot(LEFT, color = RED)

        words = VGroup(*map(TextMobject, [
            "Common midpoint",
            "Same distance apart",
            "$\\Downarrow$",
            "Rectangle",
        ]))
        words.arrange_submobjects(DOWN)
        words.to_edge(RIGHT)
        words[-1].highlight(BLUE)

        self.play(
            ShowCreation(dots),
            Write(labels)
        )
        self.play(*map(ShowCreation, lines))
        self.dither()
        self.play(*[
            ApplyMethod(
                group.shift, 
                -group[-1].get_center()+midpoint.get_center()
            )
            for group in groups
        ])
        self.play(
            ShowCreation(midpoint),
            Write(words[0])
        )
        factor = lines[0].get_length()/lines[1].get_length()        
        grower = groups[1].copy()
        new_line = grower[-1]
        new_line.scale_in_place(factor)
        grower[0].move_to(new_line.get_start())
        grower[2].next_to(grower[0], DOWN)
        grower[1].move_to(new_line.get_end())
        grower[3].next_to(grower[1], UP)

        self.play(Transform(groups[1], grower))
        self.play(Write(words[1]))
        self.dither()

        rectangle = Polygon(*[
            dots[i].get_center()
            for i in 0, 2, 1, 3
        ])
        rectangle.highlight(BLUE)
        self.play(
            ShowCreation(rectangle),
            Animation(dots)
        )
        self.play(*map(Write, words[2:]))
        self.dither()
示例#34
0
文件: chapter1.py 项目: namkam5/manim
    def house_example(self, starter_mobject, title):
        house = SVGMobject("house")
        house.set_stroke(width = 0)
        house.set_fill(BLUE_C, opacity = 1)
        house.scale_to_fit_height(3)
        house.center()
        square_footage_words = TextMobject("Square footage:")
        price_words = TextMobject("Price: ")
        square_footage = TexMobject("2{,}600\\text{ ft}^2")
        price = TextMobject("\\$300{,}000")

        house.to_edge(LEFT).shift(UP)
        square_footage_words.next_to(house, RIGHT)
        square_footage_words.shift(0.5*UP)
        square_footage_words.highlight(RED)
        price_words.next_to(square_footage_words, DOWN, aligned_edge = LEFT)
        price_words.highlight(GREEN)
        square_footage.next_to(square_footage_words)
        square_footage.highlight(RED)
        price.next_to(price_words)
        price.highlight(GREEN)

        vector = Matrix([square_footage.copy(), price.copy()])
        vector.next_to(house, RIGHT).shift(0.25*UP)
        new_square_footage, new_price = vector.get_mob_matrix().flatten()
        not_equals = TexMobject("\\ne")
        not_equals.next_to(vector)
        alt_vector = Matrix([
            TextMobject("300{,}000\\text{ ft}^2").highlight(RED),
            TextMobject("\\$2{,}600").highlight(GREEN)
        ])
        alt_vector.next_to(not_equals)

        brace = Brace(vector, RIGHT)
        two_dimensional = TextMobject("2 dimensional")
        two_dimensional.next_to(brace)
        brackets = vector.get_brackets()

        self.play(Transform(starter_mobject, house))
        self.remove(starter_mobject)
        self.add(house)
        self.add(square_footage_words)
        self.play(Write(square_footage, run_time = 2))
        self.add(price_words)
        self.play(Write(price, run_time = 2))
        self.dither()
        self.play(
            FadeOut(square_footage_words), FadeOut(price_words),
            Transform(square_footage, new_square_footage),
            Transform(price, new_price),
            Write(brackets),
            run_time = 1
        )
        self.remove(square_footage_words, price_words)
        self.dither()
        self.play(
            Write(not_equals),
            Write(alt_vector),
            run_time = 1
        )
        self.dither()
        self.play(FadeOut(not_equals), FadeOut(alt_vector))
        self.remove(not_equals, alt_vector)
        self.dither()
        self.play(
            GrowFromCenter(brace),
            Write(two_dimensional),
            run_time = 1
        )
        self.dither()

        everything = VMobject(
            house, square_footage, price, brackets, brace, 
            two_dimensional, title
        )
        self.play(ApplyMethod(everything.shift, 2*SPACE_WIDTH*LEFT))
        self.remove(everything)
示例#35
0
文件: chapter2.py 项目: snowdj/manim
    def introduce_graph(self, graph, origin):
        h_line, v_line = [
            Line(origin, origin, color=color, stroke_width=2)
            for color in MAROON_B, YELLOW
        ]

        def h_update(h_line, proportion=1):
            end = graph.point_from_proportion(proportion)
            t_axis_point = end[0] * RIGHT + origin[1] * UP
            h_line.put_start_and_end_on(t_axis_point, end)

        def v_update(v_line, proportion=1):
            end = graph.point_from_proportion(proportion)
            d_axis_point = origin[0] * RIGHT + end[1] * UP
            v_line.put_start_and_end_on(d_axis_point, end)

        car = Car()
        car.rotate(np.pi / 2)
        car.move_to(origin)
        self.add(car)
        self.play(
            ShowCreation(
                graph,
                rate_func=None,
            ),
            MoveCar(
                car,
                self.coords_to_point(0, 100),
            ),
            UpdateFromFunc(h_line, h_update),
            UpdateFromFunc(v_line, v_update),
            run_time=10,
        )
        self.dither()
        self.play(*map(FadeOut, [h_line, v_line, car]))

        #Show example vertical distance
        h_update(h_line, 0.6)
        t_dot = Dot(h_line.get_start(), color=h_line.get_color())
        t_dot.save_state()
        t_dot.move_to(self.x_axis_label_mob)
        t_dot.set_fill(opacity=0)
        dashed_h = DashedLine(*h_line.get_start_and_end())
        dashed_h.highlight(h_line.get_color())
        brace = Brace(dashed_h, RIGHT)
        brace_text = brace.get_text("Distance traveled")
        self.play(t_dot.restore)
        self.dither()
        self.play(ShowCreation(dashed_h))
        self.play(GrowFromCenter(brace), Write(brace_text))
        self.dither(2)
        self.play(*map(FadeOut, [t_dot, dashed_h, brace, brace_text]))

        #Name graph
        s_of_t = TexMobject("s(t)")
        s_of_t.next_to(graph.point_from_proportion(1),
                       DOWN + RIGHT,
                       buff=SMALL_BUFF)
        s = s_of_t[0]
        d = TexMobject("d")
        d.move_to(s, DOWN)
        d.highlight(YELLOW)

        self.play(Write(s_of_t))
        self.dither()
        s.save_state()
        self.play(Transform(s, d))
        self.dither()
        self.play(s.restore)
示例#36
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.wait()

        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.wait(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.wait(4)
示例#37
0
    def construct(self):
        clunky_deriv = TexMobject(
            "{d", "\\big(", "{df", "\\over", "dx}", "\\big)",
            "\\over", "dx }"
        )
        over_index = clunky_deriv.index_of_part(
            clunky_deriv.get_parts_by_tex("\\over")[1]
        )
        numerator = VGroup(*clunky_deriv[:over_index])
        denominator = VGroup(*clunky_deriv[over_index+1:])


        rp = clunky_deriv.get_part_by_tex("(")
        lp = clunky_deriv.get_part_by_tex(")")
        dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [
            "df", "over", "dx"
        ])
        df_over_dx = VGroup(dfs[0], overs[0], dxs[0])
        d = clunky_deriv.get_part_by_tex("d")
        d_over_dx = VGroup(d, overs[1], dxs[1])

        d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}")
        d2f_over_dx2.highlight_by_tex("dx", YELLOW)

        for mob in clunky_deriv, d2f_over_dx2:
            mob.next_to(self.teacher, UP+LEFT)

        for mob in numerator, denominator:
            circle = Circle(color = YELLOW)
            circle.replace(mob, stretch = True)
            circle.scale_in_place(1.3)
            mob.circle = circle
        dx_to_zero = TexMobject("dx \\to 0")
        dx_to_zero.highlight(YELLOW)
        dx_to_zero.next_to(clunky_deriv, UP+LEFT)

        self.student_says(
            "What's that notation?",
            target_mode = "raise_left_hand"
        )
        self.change_student_modes("confused", "raise_left_hand", "confused")
        self.play(
            FadeIn(
                clunky_deriv,
                run_time = 2,
                submobject_mode = "lagged_start"
            ),
            RemovePiCreatureBubble(self.get_students()[1]),
            self.teacher.change_mode, "raise_right_hand"
        )
        self.wait()
        self.play(ShowCreation(numerator.circle))
        self.wait()
        self.play(ReplacementTransform(
            numerator.circle,
            denominator.circle,
        ))
        self.wait()
        self.play(
            FadeOut(denominator.circle),
            Write(dx_to_zero),
            dxs.highlight, YELLOW
        )
        self.wait()
        self.play(
            FadeOut(dx_to_zero),
            *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()]
        )
        self.play(
            df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(),
            df_over_dx.move_to, d_over_dx, RIGHT,
            FadeOut(VGroup(lp, rp)),
            d_over_dx.shift, 0.8*LEFT + 0.05*UP,
        )
        self.wait()
        self.play(*[
            ReplacementTransform(
                group,
                VGroup(d2f_over_dx2.get_part_by_tex(tex))
            )
            for group, tex in [
                (VGroup(d, dfs[0]), "d^2"),
                (overs, "over"),
                (dxs, "dx"),
                (VGroup(dxs[1].copy()), "^2}"),
            ]
        ])
        self.wait(2)
        self.student_says(
            "How does one... \\\\ read that?",
            student_index = 0,
        )
        self.play(self.teacher.change, "happy")
        self.wait(2)
示例#38
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)