Beispiel #1
0
    def construct(self):
        morty = Mortimer()
        morty.scale(0.8)
        morty.to_corner(DOWN+RIGHT)
        morty.shift(0.5*LEFT)
        title = TextMobject("Associativity:")
        title.to_corner(UP+LEFT)

        lhs = TexMobject(list("(AB)C"))
        lp, a, b, rp, c = lhs.split()
        rhs = VMobject(*[m.copy() for m in a, lp, b, c, rp])
        point = VectorizedPoint()
        start = VMobject(*[m.copy() for m in point, a, b, point, c])
        for mob in lhs, rhs, start:
            mob.arrange_submobjects(buff = 0.1)
        a, lp, b, c, rp = rhs.split()
        rhs = VMobject(lp, a, b, rp, c)##Align order to lhs
        eq = TexMobject("=")
        q_marks = TextMobject("???")
        q_marks.submobject_gradient_highlight(TEAL_B, TEAL_D)
        q_marks.next_to(eq, UP)
        lhs.next_to(eq, LEFT)
        rhs.next_to(eq, RIGHT)
        start.move_to(lhs)


        self.add(morty, title)
        self.dither()
        self.play(Blink(morty))
        self.play(Write(start))
        self.dither()
        self.play(Transform(start, lhs))
        self.dither()
        self.play(
            Transform(lhs, rhs, path_arc = -np.pi),
            Write(eq)
        )
        self.play(Write(q_marks))
        self.play(Blink(morty))
        self.play(morty.change_mode, "pondering")

        lp, a, b, rp, c = start.split()
        self.show_full_matrices(morty, a, b, c, title)
Beispiel #2
0
    def scale_basis_vectors(self, new_array):
        i_hat, j_hat = self.get_basis_vectors()
        self.add_vector(i_hat)
        i_hat_label = self.label_vector(
            i_hat, "\\hat{\\imath}", 
            color = X_COLOR, 
            label_scale_factor = 1
        )
        self.add_vector(j_hat)
        j_hat_label = self.label_vector(
            j_hat, "\\hat{\\jmath}", 
            color = Y_COLOR, 
            label_scale_factor = 1
        )
        self.dither()

        x, y = new_array.get_mob_matrix().flatten()
        for coord, v, label, factor, shift_right in [
            (x, i_hat, i_hat_label, self.vector_coords[0], False), 
            (y, j_hat, j_hat_label, self.vector_coords[1], True)
            ]:
            faded_v = v.copy().fade(0.7)
            scaled_v = Vector(factor*v.get_end(), color = v.get_color())

            scaled_label = VMobject(coord.copy(), label.copy())
            scaled_label.arrange_submobjects(RIGHT, buff = 0.1)
            scaled_label.move_to(label, DOWN+RIGHT)
            scaled_label.shift((scaled_v.get_end()-v.get_end())/2)
            coord_copy = coord.copy()
            self.play(
                Transform(v.copy(), faded_v),
                Transform(v, scaled_v),
                Transform(VMobject(coord_copy, label), scaled_label),
            )
            self.dither()
            if shift_right:
                group = VMobject(v, coord_copy, label)
                self.play(ApplyMethod(
                    group.shift, self.vector_coords[0]*RIGHT
                ))
        self.dither()
Beispiel #3
0
    def construct(self):
        self.setup()
        self.plane.fade(0.3)
        self.add_unit_square(color = YELLOW_E, opacity = 0.5)
        self.add_title(
            ["The", "``determinant''", "of a transformation"],
            scale_factor = 1
        )
        self.title.split()[1].split()[1].highlight(YELLOW)

        matrix_background, matrix, det_text = self.get_matrix()
        self.add_foreground_mobject(matrix_background, matrix)

        A = TexMobject("A")
        area_label = VMobject(A.copy(), A.copy(), A)
        area_label.move_to(self.square)
        det = np.linalg.det(self.t_matrix)
        if np.round(det) == det:
            det = int(det)
        area_label_target = VMobject(
            TexMobject(str(det)), TexMobject("\\cdot"), A.copy()
        )
        if det < 1 and det > 0:
            area_label_target.scale(det)
        area_label_target.arrange_submobjects(RIGHT, buff = 0.1)
        self.add_moving_mobject(area_label, area_label_target)
        
        self.dither()
        self.apply_transposed_matrix(self.t_matrix)
        self.dither()
        det_mob_copy = area_label.split()[0].copy()
        new_det_mob = det_mob_copy.copy().scale_to_fit_height(
            det_text.split()[0].get_height()
        )
        new_det_mob.next_to(det_text, RIGHT, buff = 0.2)
        new_det_mob.add_background_rectangle()
        det_mob_copy.add_background_rectangle(opacity = 0)
        self.play(Write(det_text))
        self.play(Transform(det_mob_copy, new_det_mob))
        self.dither()
Beispiel #4
0
    def scale_basis_vectors(self, new_array):
        i_hat, j_hat = self.get_basis_vectors()
        self.add_vector(i_hat)
        i_hat_label = self.label_vector(i_hat,
                                        "\\hat{\\imath}",
                                        color=X_COLOR,
                                        label_scale_factor=1)
        self.add_vector(j_hat)
        j_hat_label = self.label_vector(j_hat,
                                        "\\hat{\\jmath}",
                                        color=Y_COLOR,
                                        label_scale_factor=1)
        self.wait()

        x, y = new_array.get_mob_matrix().flatten()
        for coord, v, label, factor, shift_right in [
            (x, i_hat, i_hat_label, self.vector_coords[0], False),
            (y, j_hat, j_hat_label, self.vector_coords[1], True)
        ]:
            faded_v = v.copy().fade(0.7)
            scaled_v = Vector(factor * v.get_end(), color=v.get_color())

            scaled_label = VMobject(coord.copy(), label.copy())
            scaled_label.arrange_submobjects(RIGHT, buff=0.1)
            scaled_label.move_to(label, DOWN + RIGHT)
            scaled_label.shift((scaled_v.get_end() - v.get_end()) / 2)
            coord_copy = coord.copy()
            self.play(
                Transform(v.copy(), faded_v),
                Transform(v, scaled_v),
                Transform(VMobject(coord_copy, label), scaled_label),
            )
            self.wait()
            if shift_right:
                group = VMobject(v, coord_copy, label)
                self.play(
                    ApplyMethod(group.shift, self.vector_coords[0] * RIGHT))
        self.wait()
Beispiel #5
0
    def construct(self):
        self.setup()
        self.plane.fade(0.3)
        self.add_unit_square(color=YELLOW_E, opacity=0.5)
        self.add_title(["The", "``determinant''", "of a transformation"],
                       scale_factor=1)
        self.title.split()[1].split()[1].highlight(YELLOW)

        matrix_background, matrix, det_text = self.get_matrix()
        self.add_foreground_mobject(matrix_background, matrix)

        A = TexMobject("A")
        area_label = VMobject(A.copy(), A.copy(), A)
        area_label.move_to(self.square)
        det = np.linalg.det(self.t_matrix)
        if np.round(det) == det:
            det = int(det)
        area_label_target = VMobject(TexMobject(str(det)),
                                     TexMobject("\\cdot"), A.copy())
        if det < 1 and det > 0:
            area_label_target.scale(det)
        area_label_target.arrange_submobjects(RIGHT, buff=0.1)
        self.add_moving_mobject(area_label, area_label_target)

        self.wait()
        self.apply_transposed_matrix(self.t_matrix)
        self.wait()
        det_mob_copy = area_label.split()[0].copy()
        new_det_mob = det_mob_copy.copy().scale_to_fit_height(
            det_text.split()[0].get_height())
        new_det_mob.next_to(det_text, RIGHT, buff=0.2)
        new_det_mob.add_background_rectangle()
        det_mob_copy.add_background_rectangle(opacity=0)
        self.play(Write(det_text))
        self.play(Transform(det_mob_copy, new_det_mob))
        self.wait()