Example #1
0
    def construct(self):
        val = 0.3
        text = TextMobject([
            "PHC", "$_n", "(",
            "%3.1f" % val, ")$", " has a ", "limit point ",
            "as $n \\to \\infty$"
        ])
        func_parts = text.copy().split()[:5]
        Mobject(*func_parts).center().to_edge(UP)
        num_str, val_str = func_parts[1], func_parts[3]
        curve = UnitInterval()
        curve.sort_points(lambda p: p[0])
        dot = Dot().shift(curve.number_to_point(val))
        arrow = Arrow(val_str, dot, buff=0.1)
        curve.add_numbers(0, 1)

        self.play(ShowCreation(curve))
        self.play(ShimmerIn(val_str), ShowCreation(arrow), ShowCreation(dot))
        self.dither()
        self.play(FadeOut(arrow), *[FadeIn(func_parts[i]) for i in 0, 1, 2, 4])
        for num in range(2, 9):
            new_curve = HilbertCurve(order=num)
            new_curve.scale(0.8)
            new_dot = Dot(new_curve.points[int(val *
                                               new_curve.get_num_points())])
            new_num_str = TexMobject(str(num)).replace(num_str)
            self.play(Transform(curve, new_curve), Transform(dot, new_dot),
                      Transform(num_str, new_num_str))
            self.dither()

        text.to_edge(UP)
        text_parts = text.split()
        for index in 1, -1:
            text_parts[index].highlight()
        starters = Mobject(*func_parts + [
            Point(mob.get_center(), stroke_width=1) for mob in text_parts[5:]
        ])
        self.play(Transform(starters, text))
        arrow = Arrow(text_parts[-2].get_bottom(), dot, buff=0.1)
        self.play(ShowCreation(arrow))
        self.dither()
Example #2
0
    def construct(self):
        series = TexMobject(
            "\\frac{1}{1} + \\frac{1}{4} + \\frac{1}{9} + \\cdots + " +\
            "\\frac{1}{n^2} + \\cdots = ", "\\,???"
        )
        series[0].gradient_highlight(BLUE_C, BLUE_B)
        series[1].highlight(YELLOW)

        question = TextMobject(
            "How should we think about\\\\",
            "$\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{n^s}$",
            "for arbitrary $s$?")
        question[1].highlight(BLUE)
        question[0].shift(SMALL_BUFF * UP)

        response = TextMobject("What do you mean by ",
                               "$\\displaystyle \\sum_{n = 1}^{\\infty}$", "?")
        response[1].highlight(BLUE)

        self.teacher_says(series)
        self.change_all_student_modes("pondering", look_at_arg=series)
        self.wait(3)
        self.play(
            FadeOut(self.teacher.bubble), self.teacher.change, "happy",
            series.scale, 0.5, series.to_corner, UP + LEFT,
            PiCreatureSays(self.students[0],
                           question,
                           target_mode="raise_left_hand"))
        self.change_student_modes(
            None,
            "confused",
            "confused",
            added_anims=[self.students[0].look_at, question])
        self.wait(2)

        self.students[0].bubble.content = VGroup()
        self.play(RemovePiCreatureBubble(self.students[0]), question.scale,
                  0.5, question.next_to, series, DOWN, MED_LARGE_BUFF, LEFT,
                  PiCreatureSays(self.teacher, response))
        self.change_all_student_modes("erm")
        self.wait(3)
Example #3
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)
Example #4
0
    def construct(self):
        randy = Randolph()
        randy.to_corner(DOWN + LEFT)
        exp, rad, log = map(TexMobject, [
            "2^3 = 8",
            "\\sqrt[3]{8} = 2",
            "\\log_2(8) = 3",
        ])
        # exp.highlight(BLUE_D)
        # rad.highlight(RED_D)
        # log.highlight(GREEN_D)
        arrow1 = DoubleArrow(DOWN, UP)
        arrow2 = arrow1.copy()
        last = exp
        for mob in arrow1, rad, arrow2, log:
            mob.next_to(last, DOWN)
            last = mob
        q_marks = VMobject(*[
            TexMobject("?!").next_to(arrow, RIGHT) for arrow in arrow1, arrow2
        ])
        q_marks.highlight(RED_D)
        everyone = VMobject(exp, rad, log, arrow1, arrow2, q_marks)
        everyone.scale(0.7)
        everyone.to_corner(UP + RIGHT)
        phrases = [
            TextMobject(["Communicate with", words]).next_to(mob, LEFT, buff=1)
            for words, mob in [("position", exp), ("a new symbol",
                                                   rad), ("a word", log)]
        ]
        for phrase, color in zip(phrases, [BLUE, RED, GREEN]):
            phrase.split()[1].highlight(color)

        self.play(ApplyMethod(randy.change_mode, "angry"))
        self.play(FadeIn(VMobject(exp, rad, log)))
        self.play(ShowCreationPerSubmobject(arrow1),
                  ShowCreationPerSubmobject(arrow2))
        self.play(Write(q_marks))
        self.wait()
        self.remove(randy)
        self.play(Write(VMobject(*phrases)))
        self.wait()
Example #5
0
    def add_axes(self):
        x_axis = Line(self.tick_width * LEFT / 2, self.width * RIGHT)
        y_axis = Line(MED_LARGE_BUFF * DOWN, self.height * UP)
        ticks = VGroup()
        labels = VGroup()
        heights = np.linspace(0, self.height, self.n_ticks + 1)
        values = np.linspace(0, self.max_value, self.n_ticks + 1)
        for y, value in zip(heights, values):
            tick = Line(LEFT, RIGHT)
            tick.scale_to_fit_width(self.tick_width)
            tick.move_to(y * UP)
            ticks.add(tick)
            label = TexMobject(str(np.round(value, 2)))
            label.scale_to_fit_height(self.y_axis_label_height)
            label.next_to(tick, LEFT, SMALL_BUFF)
            labels.add(label)
        y_axis.add(ticks)

        self.add(x_axis, y_axis, labels)
        self.x_axis, self.y_axis = x_axis, y_axis
        self.y_axis_labels = labels
    def get_music_example(self):
        rect = self.get_example_rect()

        musician = Randolph(mode="soulful_musician")
        musician.left_arm_range = [.36, .45]
        musician.arms = musician.get_arm_copies()
        guitar = musician.guitar = Guitar()
        guitar.move_to(musician)
        guitar.shift(0.31 * RIGHT + 0.6 * UP)
        musician.add(guitar, musician.arms)
        musician.scale_to_fit_height(0.7 * rect.get_height())
        musician.next_to(rect.get_bottom(), UP, SMALL_BUFF)

        probability = TexMobject("P(", "\\text{Suck }", "|",
                                 "\\text{ Good review}", ")")
        probability.highlight_by_tex("Suck", RED)
        probability.highlight_by_tex("Good", GREEN)
        probability.scale(0.5)
        probability.next_to(rect.get_top(), DOWN)

        return VGroup(rect, musician, probability)
Example #7
0
    def specifics_concepts(self):
        matrix_vector_product = TexMobject(" ".join([
            matrix_to_tex_string(EXAMPLE_TRANFORM),
            matrix_to_tex_string(TRANFORMED_VECTOR),
            "&=",
            matrix_to_tex_string([["1 \\cdot 1 + 0 \\cdot 2"],
                                  ["1 \\cdot 1 + (-1)\\cdot 2"]]),
            "\\\\ &=",
            matrix_to_tex_string([[1], [-1]]),
        ]))
        matrix_vector_product.scale_to_fit_width(SPACE_WIDTH - 0.5)
        matrix_vector_product.next_to(self.vline, LEFT)

        self.play(Write(self.numeric),
                  FadeIn(matrix_vector_product),
                  run_time=2)
        self.wait()
        self.play(Write(self.geometric, run_time=2))
        ### Paste in linear transformation
        self.wait()
        digest_locals(self)
Example #8
0
    def construct(self):
        tex_mob = TexMobject("""
            \\text{Det}\\left(\\left[
                \\begin{array}{cc}
                    1 & -1 \\\\
                    1 & 2
                \\end{array}
            \\right]\\right)
        """)
        tex_mob.scale_to_fit_height(4)
        arrow = Arrow(LEFT,
                      RIGHT,
                      stroke_width=8,
                      preserve_tip_size_when_scaling=False)
        arrow.scale(2)
        arrow.to_edge(RIGHT)
        tex_mob.next_to(arrow, LEFT)

        self.play(Write(tex_mob),
                  ShowCreation(arrow, submobject_mode="one_at_a_time"),
                  run_time=1)
Example #9
0
    def plot_result(self):
        result_label = self.final_line.copy()
        result_label.add_background_rectangle()

        point = self.plane.coords_to_point(5, 12)
        dot = Dot(point, color=GREEN)
        line = Line(self.plane.get_center_point(), point)
        line.highlight(dot.get_color())
        distance_label = TexMobject("13")
        distance_label.add_background_rectangle()
        distance_label.next_to(line.get_center(), UP + LEFT, SMALL_BUFF)

        self.play(result_label.next_to, dot, UP + LEFT, SMALL_BUFF,
                  Animation(self.final_line), DrawBorderThenFill(dot))
        self.dither()
        self.play(*[
            ReplacementTransform(m1.copy(), m2)
            for m1, m2 in [(self.line,
                            line), (self.distance_label, distance_label)]
        ])
        self.dither()
Example #10
0
 def get_coordinate_labels(self, x_vals = None, y_vals = None):
     result = []
     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 enumerate([x_vals, y_vals]):
         num_pair = [0, 0]
         for val in vals:
             if val == 0:
                 continue
             num_pair[index] = val
             point = self.num_pair_to_point(num_pair)
             num = TexMobject(str(val))
             num.add_background_rectangle()
             num.scale_to_fit_height(
                 self.written_coordinate_height
             )
             vect = DOWN if index == 0 else LEFT
             num.next_to(point, vect, buff = SMALL_BUFF)
             result.append(num)
     return result
Example #11
0
    def cannot_move_disk_onto_smaller_disk(self):
        also_not_allowed = TextMobject("Also not allowed")
        also_not_allowed.to_edge(UP)
        also_not_allowed.highlight(RED)
        cross = TexMobject("\\times")
        cross.set_fill(RED, opacity = 0.5)

        disk = self.disks[2]
        disk.save_state()
        self.move_disks_to_peg([2], 2, added_anims = [
            Transform(self.title, also_not_allowed)
        ])
        cross.replace(disk)
        self.play(FadeIn(cross))
        self.dither()
        self.play(
            FadeOut(cross),
            FadeOut(self.title),
            disk.restore
        )
        self.dither()
Example #12
0
    def construct(self):
        self.setup()
        self.add_title(["How much are", "areas", "scaled?"])
        hma, areas, scaled = self.title.split()[1].split()
        areas.highlight(YELLOW)
        blob = Blob().shift(UP + RIGHT)

        label = TextMobject("Area")
        label.highlight(YELLOW)
        label = VMobject(VectorizedPoint(label.get_left()), label)
        label.move_to(blob)
        target_label = TexMobject(["c \\cdot", "\\text{Area}"])
        target_label.split()[1].highlight(YELLOW)

        self.add_transformable_mobject(blob)
        self.add_moving_mobject(label, target_label)
        self.wait()
        self.apply_transposed_matrix([[2, -1], [1, 1]])
        arrow = Arrow(scaled, label.target.split()[0])
        self.play(ShowCreation(arrow))
        self.wait()
    def get_poker_example(self):
        rect = self.get_example_rect()
        values = IntroducePokerHand.CONFIG["community_card_values"]
        community_cards = VGroup(*map(PlayingCard, values))
        community_cards.arrange_submobjects(RIGHT)
        deck = VGroup(*[PlayingCard(turned_over=True) for x in range(5)])
        for i, card in enumerate(deck):
            card.shift(i * (0.03 * RIGHT + 0.015 * DOWN))
        deck.next_to(community_cards, LEFT)
        cards = VGroup(deck, community_cards)
        cards.scale_to_fit_width(rect.get_width() - 2 * SMALL_BUFF)
        cards.next_to(rect.get_bottom(), UP, MED_SMALL_BUFF)

        probability = TexMobject("P(", "\\text{Flush}", "|",
                                 "\\text{High bet}", ")")
        probability.highlight_by_tex("Flush", RED)
        probability.highlight_by_tex("High bet", GREEN)
        probability.scale(0.5)
        probability.next_to(rect.get_top(), DOWN)

        return VGroup(rect, probability, cards)
Example #14
0
    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.wait()
        self.play(
            morty.change_mode, "happy",
            morty.look, UP+RIGHT
        )
        self.play(Blink(morty))
        self.wait()
Example #15
0
 def count_regions(self,
                   regions,
                   mode="one_at_a_time",
                   num_offset=DEFAULT_COUNT_NUM_OFFSET,
                   run_time=DEFAULT_COUNT_RUN_TIME,
                   **unused_kwargsn):
     if mode not in ["one_at_a_time", "show_all"]:
         raise Warning("Unknown mode")
     frame_time = run_time / (len(regions))
     for region, count in zip(regions, it.count(1)):
         num_mob = TexMobject(str(count))
         num_mob.center().shift(num_offset)
         self.add(num_mob)
         self.highlight_region(region)
         self.dither(frame_time)
         if mode == "one_at_a_time":
             self.reset_background()
         self.remove(num_mob)
     self.add(num_mob)
     self.number = num_mob
     return self
Example #16
0
    def show_diameter(self):
        exceptions = [
            self.circle, 
            self.tangent_line,
            self.pc_line,
            self.right_angle_symbol
        ]
        everything = set(self.mobjects).difference(exceptions)
        everything_copy = Mobject(*everything).copy()
        light_everything = everything_copy.copy()
        dark_everything = everything_copy.copy()
        dark_everything.fade(0.8)
        bottom_point = np.array(self.c_point)
        bottom_point += 2*self.radius*DOWN
        diameter = Line(bottom_point, self.c_point)
        brace = Brace(diameter, RIGHT)
        diameter_word = TextMobject("Diameter")
        d_mob = TexMobject("D")
        diameter_word.next_to(brace)
        d_mob.next_to(diameter)

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

        self.d_mob = d_mob
        self.bottom_point = bottom_point        
Example #17
0
    def bring_in_functions(self):
        everything = VGroup(*self.get_mobjects())
        axes = Axes()
        axes.shift(2 * SPACE_WIDTH * LEFT)

        fg_scene_config = FunctionGraphScene.CONFIG
        graph = FunctionGraph(fg_scene_config["default_functions"][0])
        graph.highlight(MAROON_B)
        func_tex = TexMobject("\\frac{1}{9}x^3 - x")
        func_tex.highlight(graph.get_color())
        func_tex.shift(5.5 * RIGHT + 2 * UP)

        words = VGroup(*[
            TextMobject(words).add_background_rectangle() for words in [
                "Linear transformations",
                "Null space",
                "Dot products",
                "Eigen-everything",
            ]
        ])
        words.gradient_highlight(BLUE_B, BLUE_D)
        words.arrange_submobjects(DOWN, aligned_edge=LEFT)
        words.to_corner(UP + LEFT)
        self.play(FadeIn(words, submobject_mode="lagged_start", run_time=3))
        self.dither()
        self.play(*[
            ApplyMethod(mob.shift, 2 * SPACE_WIDTH * RIGHT)
            for mob in axes, everything
        ] + [Animation(words)])
        self.play(ShowCreation(graph), Animation(words))
        self.play(Write(func_tex, run_time=2))
        self.dither(2)

        top_word = words[0]
        words.remove(top_word)
        self.play(FadeOut(words), top_word.shift,
                  top_word.get_center()[0] * LEFT)
        self.dither()
        self.func_tex = func_tex
        self.graph = graph
Example #18
0
    def show_whole_distance_examples(self):
        dot_tuple_groups = self.integer_distance_dot_tuple_groups
        for dot_tuple_group in dot_tuple_groups:
            dot, tuple_mob = dot_tuple_group
            p0 = self.plane.get_center_point()
            p1 = dot.get_center()
            triangle = Polygon(
                p0,
                p1[0] * RIGHT + p0[1] * UP,
                p1,
                stroke_width=0,
                fill_color=BLUE,
                fill_opacity=0.75,
            )
            line = Line(p0, p1, color=dot.get_color())
            a, b = self.plane.point_to_coords(p1)
            c = int(np.sqrt(a**2 + b**2))
            hyp_label = TexMobject(str(c))
            hyp_label.add_background_rectangle()
            hyp_label.next_to(triangle.get_center(),
                              UP + LEFT,
                              buff=SMALL_BUFF)
            line.add(hyp_label)

            dot_tuple_group.triangle = triangle
            dot_tuple_group.line = line

        group = dot_tuple_groups[0]

        self.play(Write(group.line))
        self.play(FadeIn(group.triangle), Animation(group.line))
        self.dither(2)
        for new_group in dot_tuple_groups[1:]:
            self.play(
                Transform(group, new_group),
                Transform(group.triangle, new_group.triangle),
                Transform(group.line, new_group.line),
            )
            self.dither(2)
        self.play(*map(FadeOut, [group, group.triangle, group.line]))
Example #19
0
    def construct(self):
        n_terms = 4
        def func((x, y, ignore)):
            z = complex(x, y)                                    
            if (np.abs(x%1 - 0.5)<0.01 and y < 0.01) or np.abs(z)<0.01:
                return ORIGIN
            out_z = 1./(2*np.tan(np.pi*z)*(z**2))
            return out_z.real*RIGHT - out_z.imag*UP
        arrows = Mobject(*[
            Arrow(ORIGIN, np.sqrt(2)*point)
            for point in compass_directions(4, RIGHT+UP)
        ])
        arrows.highlight(YELLOW)
        arrows.ingest_submobjects()
        all_arrows = Mobject(*[
            arrows.copy().scale(0.3/(x)).shift(x*RIGHT)
            for x in range(1, n_terms+2)
        ])
        terms = TexMobject([
            "\\dfrac{1}{%d^2} + "%(x+1)
            for x in range(n_terms)
        ]+["\\cdots"])
        terms.shift(2*UP)
        plane = NumberPlane(color = BLUE_E)
        axes = Mobject(NumberLine(), NumberLine().rotate(np.pi/2))
        axes.highlight(WHITE)

        for term in terms.split():
            self.play(ShimmerIn(term, run_time = 0.5))
        self.dither()
        self.play(ShowCreation(plane), ShowCreation(axes))
        self.play(*[
            Transform(*pair)
            for pair in zip(terms.split(), all_arrows.split())
        ])
        self.play(PhaseFlow(
            func, plane,
            run_time = 5,
            virtual_time = 8
        ))
Example #20
0
    def let_one_day_pass(self, run_time=2):
        all_creatures = self.get_pi_creatures()
        on_screen_creatures = self.get_on_screen_pi_creatures()
        low_i = len(on_screen_creatures)
        high_i = min(2 * low_i, len(all_creatures))
        new_creatures = VGroup(*all_creatures[low_i:high_i])

        to_children_anims = []
        growing_anims = []
        for old_pi, pi in zip(on_screen_creatures, new_creatures):
            pi.save_state()
            child = pi.copy()
            child.scale(0.25, about_point=child.get_bottom())
            child.eyes.scale(1.5, about_point=child.eyes.get_bottom())
            pi.move_to(old_pi)
            pi.set_fill(opacity=0)

            index = list(new_creatures).index(pi)
            prop = float(index) / len(new_creatures)
            alpha = np.clip(len(new_creatures) / 8.0, 0, 0.5)
            rate_func = squish_rate_func(smooth, alpha * prop,
                                         alpha * prop + (1 - alpha))

            to_child_anim = Transform(pi, child, rate_func=rate_func)
            to_child_anim.update(1)
            growing_anim = ApplyMethod(pi.restore, rate_func=rate_func)
            to_child_anim.update(0)

            to_children_anims.append(to_child_anim)
            growing_anims.append(growing_anim)

        time = self.t_expression[-1]
        total_new_creatures = len(on_screen_creatures) + len(new_creatures)
        new_time = TexMobject(str(int(np.log2(total_new_creatures))))
        new_time.move_to(time, LEFT)

        growing_anims.append(Transform(time, new_time))

        self.play(*to_children_anims, run_time=run_time / 2.0)
        self.play(*growing_anims, run_time=run_time / 2.0)
Example #21
0
    def construct(self):
        CycloidScene.construct(self)

        equation = TexMobject([
            "\\dfrac{\\sin(\\theta)}{\\sqrt{y}}",
            "= \\text{constant}"
        ])
        sin_sqrt, const = equation.split()
        new_eq = equation.copy()
        new_eq.to_edge(UP, buff = 1.3)
        cycloid_word = TextMobject("Cycloid")
        arrow = Arrow(2*UP, cycloid_word)
        arrow.reverse_points()
        q_mark = TextMobject("?")

        self.play(*map(ShimmerIn, equation.split()))
        self.wait()
        self.play(
            ApplyMethod(equation.shift, 2.2*UP),
            ShowCreation(arrow)
        )
        q_mark.next_to(sin_sqrt)
        self.play(ShimmerIn(cycloid_word))
        self.wait()
        self.grow_parts()
        self.draw_cycloid()
        self.wait()
        extra_terms = [const, arrow, cycloid_word]
        self.play(*[
            Transform(mob, q_mark)
            for mob in extra_terms
        ])
        self.remove(*extra_terms)
        self.roll_back()
        q_marks, arrows = self.get_q_marks_and_arrows(sin_sqrt)
        self.draw_cycloid(3, 
            ShowCreation(q_marks),
            ShowCreation(arrows)
        )
        self.wait()
Example #22
0
    def construct(self):
        i_to = TexMobject("\\hat{\\imath} \\to").highlight(X_COLOR)
        j_to = TexMobject("\\hat{\\jmath} \\to").highlight(Y_COLOR)
        k_to = TexMobject("\\hat{k} \\to").highlight(Z_COLOR)
        i_array = Matrix(self.col1)
        j_array = Matrix(self.col2)
        k_array = Matrix(self.col3)
        everything = VMobject(
            i_to,
            i_array,
            TexMobject("=").highlight(BLACK),
            j_to,
            j_array,
            TexMobject("=").highlight(BLACK),
            k_to,
            k_array,
            TexMobject("=").highlight(BLACK),
        )
        everything.arrange_submobjects(RIGHT, buff=0.1)
        everything.scale_to_fit_width(2 * SPACE_WIDTH - 1)
        everything.to_edge(DOWN)

        i_array.highlight(X_COLOR)
        j_array.highlight(Y_COLOR)
        k_array.highlight(Z_COLOR)
        arrays = [i_array, j_array, k_array]
        matrix = Matrix(
            reduce(lambda a1, a2: np.append(a1, a2, axis=1),
                   [m.copy().get_mob_matrix() for m in arrays]))
        matrix.to_edge(DOWN)

        start_entries = reduce(op.add,
                               map(lambda a: a.get_entries().split(), arrays))
        target_entries = matrix.get_mob_matrix().transpose().flatten()
        start_l_bracket = i_array.get_brackets().split()[0]
        start_r_bracket = k_array.get_brackets().split()[1]
        start_brackets = VMobject(start_l_bracket, start_r_bracket)
        target_bracketes = matrix.get_brackets()

        for mob in everything.split():
            self.play(Write(mob, run_time=1))
        self.wait()
        self.play(
            FadeOut(everything),
            Transform(VMobject(*start_entries), VMobject(*target_entries)),
            Transform(start_brackets, target_bracketes))
        self.wait()
Example #23
0
    def scale_vector(self, v, factor, v_label, v_name="v", factor_tex=None):
        starting_mobjects = list(self.mobjects)

        if factor_tex is None:
            factor_tex = str(factor)
        scaled_vector = self.add_vector(factor * v.get_end(), animate=False)
        self.remove(scaled_vector)
        label_tex = "%s\\vec{\\textbf{%s}}" % (factor_tex, v_name)
        label = self.label_vector(scaled_vector,
                                  label_tex,
                                  animate=False,
                                  add_to_vector=False)
        self.remove(label)
        factor_mob = TexMobject(factor_tex)
        if factor_mob.get_height() > 1:
            factor_mob.scale_to_fit_height(0.9)
        if factor_mob.get_width() > 1:
            factor_mob.scale_to_fit_width(0.9)
        factor_mob.shift(1.5 * RIGHT + 2.5 * UP)

        num_factor_parts = len(factor_mob.split())
        factor_mob_parts_in_label = label.split()[:num_factor_parts]
        label_remainder_parts = label.split()[num_factor_parts:]
        factor_in_label = VMobject(*factor_mob_parts_in_label)
        label_remainder = VMobject(*label_remainder_parts)

        self.play(Write(factor_mob, run_time=1))
        self.dither()
        self.play(
            ApplyMethod(v.copy().highlight, DARK_GREY),
            ApplyMethod(v_label.copy().highlight, DARK_GREY),
            Transform(factor_mob, factor_in_label),
            Transform(v.copy(), scaled_vector),
            Transform(v_label.copy(), label_remainder),
        )
        self.dither(2)

        self.clear()
        self.add(*starting_mobjects)
Example #24
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_BUFF)
     return VGroup(line, brace, text)
Example #25
0
 def get_coordinate_labels(self, x_vals = None, y_vals = None):
     coordinate_labels = VGroup()
     if x_vals == None:
         x_vals = range(-int(self.x_radius), int(self.x_radius)+1)
     if y_vals == None:
         y_vals = range(-int(self.y_radius), int(self.y_radius)+1)
     for index, vals in enumerate([x_vals, y_vals]):
         num_pair = [0, 0]
         for val in vals:
             if val == 0:
                 continue
             num_pair[index] = val
             point = self.coords_to_point(*num_pair)
             num = TexMobject(str(val))
             num.add_background_rectangle()
             num.scale_to_fit_height(
                 self.written_coordinate_height
             )
             num.next_to(point, DOWN+LEFT, buff = SMALL_BUFF)
             coordinate_labels.add(num)
     self.coordinate_labels = coordinate_labels
     return coordinate_labels
Example #26
0
    def draw_triangle(self):
        hyp_length = TexMobject("u", "^2", "+", "v", "^2")
        hyp_length.highlight_by_tex("u", U_COLOR)
        hyp_length.highlight_by_tex("v", V_COLOR)
        hyp_length.add_background_rectangle()
        line = self.square_line
        hyp_length.next_to(line.get_center(), UP, SMALL_BUFF)
        hyp_length.rotate(line.get_angle(), about_point=line.get_center())
        triangle = Polygon(
            ORIGIN,
            RIGHT,
            RIGHT + UP,
            stroke_width=0,
            fill_color=MAROON_B,
            fill_opacity=0.5,
        )
        triangle.replace(line, stretch=True)

        self.play(Write(hyp_length))
        self.dither()
        self.play(FadeIn(triangle))
        self.dither()
Example #27
0
    def side_project(self, morty):
        rect = PictureInPictureFrame()
        rect.next_to(morty, UP + LEFT)
        side_project = TextMobject("Side project")
        side_project.next_to(rect, UP)
        dollar_sign = TexMobject("\\$")
        cross = VGroup(
            *[Line(vect, -vect, color=RED) for vect in UP + RIGHT, UP + LEFT])
        cross.scale_to_fit_height(dollar_sign.get_height())
        no_money = VGroup(dollar_sign, cross)
        no_money.next_to(rect, DOWN)

        self.play(morty.change_mode, "raise_right_hand", morty.look_at, rect)
        self.play(Write(side_project), ShowCreation(rect))
        self.dither()
        self.play(Blink(morty))
        self.dither()
        self.play(Write(dollar_sign))
        self.play(ShowCreation(cross))

        self.screen_title = side_project
        self.cross = cross
Example #28
0
    def talk_though_sine(self):
        x_axis = self.x_slider[0]
        graph = FunctionGraph(np.sin, x_min=0, x_max=np.pi, color=SINE_COLOR)
        scale_factor = self.x_slider.get_width() / self.slider_x_max
        graph.scale(scale_factor)
        graph.move_to(x_axis.number_to_point(0), LEFT)

        label = TexMobject("\\sin(x)")
        label.highlight(SINE_COLOR)
        label.next_to(graph, UP)

        y_axis = x_axis.copy()
        y_axis.remove(*y_axis.numbers)

        v_line = Line(ORIGIN, UP, color=WHITE, stroke_width=2)

        def v_line_update(v_line):
            x = x_axis.point_to_number(self.x_slider[1].get_top())
            v_line.scale_to_fit_height(np.sin(x) * scale_factor)
            v_line.move_to(x_axis.number_to_point(x), DOWN)

        v_line_update(v_line)

        self.play(Rotate(y_axis, np.pi / 2, about_point=y_axis.get_left()),
                  Animation(x_axis))
        self.play(ShowCreation(graph), Write(label, run_time=1))
        self.play(ShowCreation(v_line))
        for x, rt in zip([0.25, np.pi / 2, 3, self.default_x], [2, 4, 4, 2]):
            self.animate_x_change(
                x,
                run_time=rt,
                added_anims=[UpdateFromFunc(v_line, v_line_update)])
            self.dither()
        self.play(*it.chain(map(FadeOut, [y_axis, graph, label, v_line]),
                            [Animation(x_axis)]))
        self.dither()
        for x in 1, 0.5, self.default_x:
            self.animate_x_change(x)
        self.dither()
Example #29
0
def matrix_multiplication():
    return TexMobject("""
        \\left[
            \\begin{array}{cc}
                a & b \\\\
                c & d
            \\end{array}
        \\right]
        \\left[
            \\begin{array}{cc}
                e & f \\\\
                g & h
            \\end{array}
        \\right]
        = 
        \\left[
            \\begin{array}{cc}
                ae + bg & af + bh \\\\
                ce + dg & cf + dh
            \\end{array}
        \\right]
    """)
Example #30
0
 def put_on_vertex(self, index, value):
     assert (index in [0, 1, 2])
     if value is None:
         value = VectorizedPoint()
     if isinstance(value, numbers.Number):
         value = str(value)
     if isinstance(value, str):
         value = TexMobject(value)
     if isinstance(value, TOP):
         return self.put_top_on_vertix(index, value)
     self.rescale_corner_mobject(value)
     value.center()
     if index == 0:
         offset = -value.get_corner(UP + RIGHT)
     elif index == 1:
         offset = -value.get_bottom()
     elif index == 2:
         offset = -value.get_corner(UP + LEFT)
     value.shift(self.offset_multiple * offset)
     anchors = self.triangle.get_anchors_and_handles()[0]
     value.shift(anchors[index])
     return value