Beispiel #1
0
    def get_division_change_animations(
        self, sample_space, parts, p_list,
        dimension = 1,
        new_label_kwargs = None,
        **kwargs
        ):
        if new_label_kwargs is None:
            new_label_kwargs = {}
        anims = []
        p_list = sample_space.complete_p_list(p_list)
        space_copy = sample_space.copy()

        vect = DOWN if dimension == 1 else RIGHT
        parts.generate_target()
        for part, p in zip(parts.target, p_list):
            part.replace(space_copy, stretch = True)
            part.stretch(p, dimension)
        parts.target.arrange_submobjects(vect, buff = 0)
        parts.target.move_to(space_copy)
        anims.append(MoveToTarget(parts))
        if hasattr(parts,  "labels") and parts.labels is not None:
            label_kwargs = parts.label_kwargs
            label_kwargs.update(new_label_kwargs)
            new_braces, new_labels = sample_space.get_subdivision_braces_and_labels(
                parts.target, **label_kwargs
            )
            anims += [
                Transform(parts.braces, new_braces),
                Transform(parts.labels, new_labels),
            ]
        return anims
Beispiel #2
0
    def revisit_koch(self):
        words = map(TextMobject, [
            "First, look at how one section of this curve is made.",
            "This pattern of four lines is the ``seed''",
            "With each iteration, every straight line is \
            replaced with an appropriately small copy of the seed",
        ])
        for text in words:
            text.to_edge(UP)

        self.add(words[0])
        curve = StraightKoch(order=self.max_order)
        self.play(Transform(curve, StraightKoch(order=1), run_time=5))
        self.remove(words[0])
        self.add(words[1])
        self.wait(4)
        self.remove(words[1])
        self.add(words[2])
        self.wait(3)
        for order in range(2, self.max_order):
            self.play(Transform(curve, StraightKoch(order=order)))
            if order == 2:
                self.wait(2)
            elif order == 3:
                self.wait()
        self.clear()
Beispiel #3
0
    def choose_two_special_numbers(self):
        two_and_four_text = TextMobject("现在选择两个特殊的数...")
        two_and_four_text.set_color(YELLOW)
        two_and_four_text.to_edge(UP)
        self.play(Transform(self.anything_text, two_and_four_text))
        self.wait()

        two_equation = self.equation
        four_equation = two_equation.copy()
        self.play(four_equation.to_edge, RIGHT, self.tower_edge_buff)
        self.wait()

        nums = [2, 4]
        colors = [GREEN, RED]
        equations = [two_equation, four_equation]
        targets = [equation[1][1] for equation in equations]
        two, four = num_texs = [
            TexMobject(str(num)).set_color(color).match_height(target).move_to(target)
            for num, color, equation, target in zip(nums, colors, equations, targets)
        ]

        for N_tex, num_tex in zip(targets, num_texs):
            self.play(Transform(N_tex, num_tex))
            self.wait(0.5)
        self.wait(0.5)

        self.nums = nums
        self.colors = colors
        self.equations = equations
        self.x_towers = VGroup(*[equation[0] for equation in equations])
Beispiel #4
0
    def construct(self):
        hilbert_curves, snake_curves = [
            [
                CurveClass(order = n)
                for n in range(2, 7)
            ]
            for CurveClass in HilbertCurve, SnakeCurve
        ]
        for curve in hilbert_curves+snake_curves:
            curve.scale(0.8)
        for curve in hilbert_curves:
            curve.to_edge(LEFT)
        for curve in snake_curves:
            curve.to_edge(RIGHT)
        greater_than = TexMobject(">")
        question_mark = TextMobject("?")
        question_mark.next_to(greater_than, UP)

        self.add(greater_than, question_mark)
        hilbert_curve = hilbert_curves[0]
        snake_curve = snake_curves[0]
        for new_hc, new_sc in zip(hilbert_curves[1:], snake_curves[1:]):
            self.play(*[
                Transform(hilbert_curve, new_hc),
                Transform(snake_curve, new_sc)
            ])
            self.dither()
Beispiel #5
0
 def construct(self):
     start_curve = SnakeCurve(order = 6)
     end_curve = SnakeCurve(order = 7)
     start_dots, end_dots = [
         Mobject(*[
             Dot(
                 curve.points[int(x*curve.get_num_points())],
                 color = color
             )
             for x, color in [
                 (0.202, GREEN),
                 (0.48, BLUE),
                 (0.7, RED)
             ]
         ])
         for curve in start_curve, end_curve
     ]
     self.add(start_curve)
     self.dither()
     self.play(
         ShowCreation(start_dots, run_time = 2),
         ApplyMethod(start_curve.fade)
     )
     end_curve.fade()
     self.play(
         Transform(start_curve, end_curve),
         Transform(start_dots, end_dots)
     )
     self.dither()
Beispiel #6
0
    def construct(self):
        low_res = ImageMobject("low_resolution_lion", invert = False)
        high_res = ImageMobject("Lion", invert = False)
        grid = get_grid().scale(0.8)
        for mob in low_res, high_res:
            mob.replace(grid, stretch = True)
        side_brace = Brace(low_res, LEFT)
        top_brace = Brace(low_res, UP)
        top_words = TextMobject("256 Px", size = "\\normal")
        side_words = top_words.copy().rotate(np.pi/2)
        top_words.next_to(top_brace, UP)
        side_words.next_to(side_brace, LEFT)

        self.add(high_res)
        self.dither()
        self.play(DelayByOrder(Transform(high_res, low_res)))
        self.dither()
        self.play(
            GrowFromCenter(top_brace),
            GrowFromCenter(side_brace),
            ShimmerIn(top_words),
            ShimmerIn(side_words)
        )
        self.dither()
        for mob in grid, high_res:
            mob.sort_points(np.linalg.norm)
        self.play(DelayByOrder(Transform(high_res, grid)))
        self.dither()
Beispiel #7
0
    def construct(self):
        # Setup
        line = NumberLine()
        house = House()
        drunk = Drunk(direction=RIGHT)
        house.place_on(ORIGIN)
        drunk.step_on(ORIGIN)
        t_equals = TexMobject("t = ")
        time = TexMobject("0")
        time.next_to(t_equals, RIGHT, buff=0.15)
        VGroup(t_equals, time).next_to(line, DOWN, buff=0.5)
        old_drunk = drunk.copy()
        old_time = time.copy()
        self.add(house, line, drunk, t_equals)

        # Start wandering
        for k in range(20):
            new_time = TexMobject("%s" % str(k + 1))
            new_time.next_to(t_equals, RIGHT, buff=0.15)
            self.play(
                DrunkWander(drunk, random.choice([-1, 1]), total_time=0.5),
                Transform(time,
                          new_time,
                          rate_func=snap_head_and_tail(smooth),
                          run_time=0.5),
            )
        self.wait()

        # Reset
        self.play(Transform(time, old_time), Transform(drunk, old_drunk))
        self.wait()
Beispiel #8
0
    def construct(self):
        grids = [
            Grid(
                2**order, 2**order,
                stroke_width = 1
            ).shift(0.3*DOWN)
            for order in 6, 7
        ]
        grid = grids[0]
        side_brace = Brace(grid, LEFT)
        top_brace = Brace(grid, UP)
        top_words = TextMobject("256")
        new_top_words = TextMobject("512")
        side_words = top_words.copy()
        new_side_words = new_top_words.copy()
        for words in top_words, new_top_words:
            words.next_to(top_brace, UP, buff = 0.1)
        for words in side_words, new_side_words:
            words.next_to(side_brace, LEFT)

        self.add(grid)
        self.play(
            GrowFromCenter(side_brace),
            GrowFromCenter(top_brace),
            ShimmerIn(top_words),
            ShimmerIn(side_words)
        )
        self.dither()
        self.play(
            DelayByOrder(Transform(*grids)),
            Transform(top_words, new_top_words),
            Transform(side_words, new_side_words)
        )
        self.dither()
Beispiel #9
0
 def __init__(self, mobject, **kwargs):
     target = mobject.copy()
     Transform.__init__(self, mobject, target, **kwargs)
     self.starting_mobject.fade(1)
     if isinstance(self.starting_mobject, VMobject):
         self.starting_mobject.set_stroke(width=0)
         self.starting_mobject.set_fill(opacity=0)
Beispiel #10
0
    def construct(self):
        curve = HilbertCurve(order = 6)
        curve.highlight(WHITE)
        colored_curve = curve.copy()
        colored_curve.thin_out(3)
        lion = ImageMobject("lion", invert = False)
        lion.replace(curve, stretch = True)
        sparce_lion = lion.copy()
        sparce_lion.thin_out(100)
        distance_matrix = cdist(colored_curve.points, sparce_lion.points)
        closest_point_indices = np.apply_along_axis(
            np.argmin, 1, distance_matrix
        )
        colored_curve.rgbas = sparce_lion.rgbas[closest_point_indices]
        line = Line(5*LEFT, 5*RIGHT)
        Mobject.align_data(line, colored_curve)
        line.rgbas = colored_curve.rgbas

        self.add(lion)
        self.play(ShowCreation(curve, run_time = 3))
        self.play(
            FadeOut(lion),
            Transform(curve, colored_curve),
            run_time = 3
        )
        self.wait()
        self.play(Transform(curve, line, run_time = 5))
        self.wait()
Beispiel #11
0
    def show_angles(self):
        words = TextMobject("""
            Let's see what happens as we change
            the angle in this seed
        """)
        words.to_edge(UP)
        koch, sharper_koch, duller_koch = curves = [
            CurveClass(order=1)
            for CurveClass in StraightKoch, SharperKoch, DullerKoch
        ]
        arcs = [
            Arc(2 * (np.pi / 2 - curve.angle),
                radius=r,
                start_angle=np.pi + curve.angle).shift(
                    curve.points[curve.get_num_points() / 2])
            for curve, r in zip(curves, [0.6, 0.7, 0.4])
        ]
        theta = TexMobject("\\theta")
        theta.shift(arcs[0].get_center() + 2.5 * DOWN)
        arrow = Arrow(theta, arcs[0])

        self.add(words, koch)
        self.play(ShowCreation(arcs[0]))
        self.play(ShowCreation(arrow), ShimmerIn(theta))
        self.wait(2)
        self.remove(theta, arrow)
        self.play(
            Transform(koch, duller_koch),
            Transform(arcs[0], arcs[2]),
        )
        self.play(
            Transform(koch, sharper_koch),
            Transform(arcs[0], arcs[1]),
        )
        self.clear()
Beispiel #12
0
        def update_group(group, alpha):
            area, left_v_line, left_T_label, right_v_line, right_T_label = group
            t_min = interpolate(curr_t_min, new_t_min, alpha)
            t_max = interpolate(curr_t_max, new_t_max, alpha)
            new_area = self.get_area(graph, t_min, t_max)

            new_left_v_line = self.get_vertical_line_to_graph(t_min, graph)
            new_left_v_line.set_color(left_v_line.get_color())
            left_T_label.move_to(new_left_v_line.get_bottom(), UP)

            new_right_v_line = self.get_vertical_line_to_graph(t_max, graph)
            new_right_v_line.set_color(right_v_line.get_color())
            right_T_label.move_to(new_right_v_line.get_bottom(), UP)

            # Fade close to 0
            if fade_close_to_origin:
                if len(left_T_label) > 0:
                    left_T_label[0].set_fill(opacity=min(1, np.abs(t_min)))
                if len(right_T_label) > 0:
                    right_T_label[0].set_fill(opacity=min(1, np.abs(t_max)))

            Transform(area, new_area).update(1)
            Transform(left_v_line, new_left_v_line).update(1)
            Transform(right_v_line, new_right_v_line).update(1)
            return group
Beispiel #13
0
    def finite_analog(self, left_mob, arrow, right_mob):
        self.clear()
        self.add(left_mob, arrow, right_mob)
        ex = TextMobject("\\times")
        ex.highlight(RED)
        # ex.shift(arrow.get_center())
        middle = TexMobject("\\sum_{n=0}^N 2^n \\equiv -1 \\mod 2^{N+1}")
        finite_analog = TextMobject("Finite analog")
        finite_analog.scale(0.8)
        brace = Brace(middle, UP)
        finite_analog.next_to(brace, UP)
        new_left = left_mob.copy().to_edge(LEFT)
        new_right = right_mob.copy().to_edge(RIGHT)
        left_arrow, right_arrow = [
            Arrow(mob1.get_right()[0] * RIGHT,
                  mob2.get_left()[0] * RIGHT,
                  buff=0)
            for mob1, mob2 in [(new_left, middle), (middle, new_right)]
        ]
        for mob in ex, middle:
            mob.sort_points(np.linalg.norm)

        self.play(GrowFromCenter(ex))
        self.wait()
        self.play(Transform(left_mob, new_left),
                  Transform(arrow.copy(), left_arrow),
                  DelayByOrder(Transform(ex, middle)),
                  Transform(arrow, right_arrow),
                  Transform(right_mob, new_right))
        self.play(GrowFromCenter(brace), ShimmerIn(finite_analog))
        self.wait()
        self.equivalence(left_mob, left_arrow,
                         Mobject(middle, brace, finite_analog))
Beispiel #14
0
 def __init__(self, mobject, **kwargs):
     target = mobject.copy()
     Transform.__init__(self, mobject, target, **kwargs)
     self.starting_mobject.fade(1)
     if isinstance(self.starting_mobject, VMobject):
         self.starting_mobject.set_stroke(width = 0)
         self.starting_mobject.set_fill(opacity = 0)
Beispiel #15
0
    def construct(self):
        string = Vibrate(color = BLUE_D, run_time = 5)
        picture = ImageMobject("lion", invert = False)
        picture.scale(0.8)
        picture_copy = picture.copy()
        picture.sort_points(np.linalg.norm)
        string.mobject.sort_points(lambda p : -np.linalg.norm(p))

        self.add(picture)
        self.dither()
        self.play(Transform(
            picture, string.mobject,
            run_time = 3,
            rate_func = rush_into
        ))
        self.remove(picture)
        self.play(string)

        for mob in picture_copy, string.mobject:
            mob.sort_points(lambda p : np.linalg.norm(p)%1)

        self.play(Transform(
            string.mobject, picture_copy,
            run_time = 5,
            rate_func = rush_from
        ))
    def construct(self):
        europe = ImageMobject("Europe", use_cache = False)
        self.add(europe)
        self.freeze_background()

        mathematicians = [
            ("Newton", [-1.75, -0.75, 0]),
            ("Jacob_Bernoulli",[-0.75, -1.75, 0]),
            ("Ehrenfried_von_Tschirnhaus",[0.5, -0.5, 0]),
            ("Gottfried_Wilhelm_von_Leibniz",[0.2, -1.75, 0]),
            ("Guillaume_de_L'Hopital", [-1.75, -1.25, 0]),
        ]

        for name, point in mathematicians:
            man = ImageMobject(name, invert = False)
            if name == "Newton":
                name = "Isaac_Newton"
            name_mob = TextMobject(name.replace("_", " "))
            name_mob.to_corner(UP+LEFT, buff=0.75)
            self.add(name_mob)
            man.scale_to_fit_height(4)
            mobject = Point(man.get_corner(UP+LEFT))
            self.play(Transform(mobject, man))
            man.scale(0.2)
            man.shift(point)
            self.play(Transform(mobject, man))
            self.remove(name_mob)
Beispiel #17
0
    def construct(self):
        names = [
            "Johann_Bernoulli2", "Jacob_Bernoulli",
            "Gottfried_Wilhelm_von_Leibniz", "Newton"
        ]
        guys = [ImageMobject(name, invert=False) for name in names]
        johann = guys[0]
        johann.scale(0.8)
        pensive_johann = johann.copy()
        pensive_johann.scale(0.25)
        pensive_johann.to_corner(DOWN + LEFT)
        comparitive_johann = johann.copy()
        template = Square(side_length=2)
        comparitive_johann.replace(template)
        comparitive_johann.shift(UP + LEFT)
        greater_than = TexMobject(">")
        greater_than.next_to(comparitive_johann)
        for guy, name in zip(guys, names)[1:]:
            guy.replace(template)
            guy.next_to(greater_than)
            name_mob = TextMobject(name.replace("_", " "))
            name_mob.scale(0.5)
            name_mob.next_to(guy, DOWN)
            guy.name_mob = name_mob
            guy.sort_points(lambda p: np.dot(p, DOWN + RIGHT))
        bubble = ThoughtBubble(initial_width=12)
        bubble.stretch_to_fit_height(6)
        bubble.ingest_submobjects()
        bubble.pin_to(pensive_johann)
        bubble.shift(DOWN)
        point = Point(johann.get_corner(UP + RIGHT))
        upper_point = Point(comparitive_johann.get_corner(UP + RIGHT))
        lightbulb = ImageMobject("Lightbulb", invert=False)
        lightbulb.scale(0.1)
        lightbulb.sort_points(np.linalg.norm)
        lightbulb.next_to(upper_point, RIGHT)

        self.add(johann)
        self.wait()
        self.play(Transform(johann, pensive_johann),
                  Transform(point, bubble),
                  run_time=2)
        self.remove(point)
        self.add(bubble)
        weakling = guys[1]
        self.play(FadeIn(comparitive_johann), ShowCreation(greater_than),
                  FadeIn(weakling))
        self.wait(2)
        for guy in guys[2:]:
            self.play(DelayByOrder(Transform(weakling, upper_point)))
            self.play(FadeIn(guy), ShimmerIn(guy.name_mob))
            self.wait(3)
            self.remove(guy.name_mob)
            weakling = guy
        self.play(FadeOut(weakling), FadeOut(greater_than))
        self.play(ShowCreation(lightbulb))
        self.wait()
        self.play(FadeOut(comparitive_johann), FadeOut(lightbulb))
        self.play(ApplyMethod(Mobject(johann, bubble).scale, 10, run_time=3))
Beispiel #18
0
    def construct(self):
        # Setup
        pos_axis = NumberLine(x_min=-3.5, x_max=3.5, color=WHITE)
        pos_axis.rotate(np.pi / 2)
        pos_axis.add_tip()
        time_axis = NumberLine(x_min=0, x_max=9.5, color=WHITE)
        time_axis.add_tip()
        house = House()
        house.rotate(np.pi / 2)
        house.place_on(pos_axis.number_to_point(0))
        zero_drunk = Drunk(direction=UP, color=self.zero_color)
        zero_drunk.step_on(pos_axis.number_to_point(0))
        neg_drunk = Drunk(direction=UP, color=self.neg_color)
        neg_drunk.step_on(pos_axis.number_to_point(0))
        group = VGroup(house, VGroup(pos_axis, time_axis), zero_drunk,
                       neg_drunk)
        group.to_edge(LEFT)
        pos_text = TextMobject("位置")
        pos_text.next_to(pos_axis.number_to_point(3.5), LEFT)
        time_text = TextMobject("时间")
        time_text.next_to(time_axis.number_to_point(9.5), DOWN)
        self.add(group, pos_text, time_text)
        old_zero_drunk = zero_drunk.copy()
        old_neg_drunk = neg_drunk.copy()

        # Start Wandering
        zero_sequence = "UUUDDDDU"
        zero_walk = RandomWalk1DArrow(
            zero_sequence,
            up_color=self.zero_color,
            down_color=self.zero_color,
        )
        zero_walk.move_start_to(pos_axis.number_to_point(0))
        neg_sequence = "DDUDDUDU"
        neg_walk = RandomWalk1DArrow(
            neg_sequence,
            up_color=self.neg_color,
            down_color=self.neg_color,
        )
        neg_walk.move_start_to(pos_axis.number_to_point(0))
        for k, (zero_char,
                neg_char) in enumerate(zip(zero_sequence, neg_sequence)):
            zero_increment = 1 if zero_char == "U" else -1
            neg_increment = 1 if neg_char == "U" else -1
            zero_arrow = zero_walk.get_arrow_by_number(k)
            neg_arrow = neg_walk.get_arrow_by_number(k)
            self.play(DrunkWander(zero_drunk, zero_increment, direction=UP),
                      DrunkWander(neg_drunk, neg_increment, direction=UP),
                      ShowCreation(zero_arrow), ShowCreation(neg_arrow))
        self.wait()

        # Reset
        self.play(
            Transform(zero_drunk, old_zero_drunk),
            Transform(neg_drunk, old_neg_drunk),
            FadeOut(zero_walk),
            FadeOut(neg_walk),
        )
        self.wait()
Beispiel #19
0
 def __init__(self, mobject, direction=None, **kwargs):
     digest_config(self, kwargs)
     target = mobject.copy()
     if direction is None:
         direction = self.direction
     mobject.shift(direction)
     mobject.fade(1)
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #20
0
 def __init__(self, mobject, point, **kwargs):
     digest_config(self, kwargs)
     target = mobject.copy()
     point_mob = VectorizedPoint(point)
     if self.point_color:
         point_mob.set_color(self.point_color)
     mobject.replace(point_mob)
     mobject.set_color(point_mob.get_color())
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #21
0
 def __init__(self, mobject, point, **kwargs):
     digest_config(self, kwargs)
     target = mobject.copy()
     point_mob = VectorizedPoint(point)
     if self.point_color:
         point_mob.set_color(self.point_color)
     mobject.replace(point_mob)
     mobject.set_color(point_mob.get_color())
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #22
0
 def construct(self):
     curve = HilbertCurve(order=1)
     words = TextMobject("``Hilbert Curve''")
     words.to_edge(UP, buff=0.2)
     self.play(ShimmerIn(words),
               Transform(curve, HilbertCurve(order=2)),
               run_time=2)
     for n in range(3, 8):
         self.play(Transform(curve, HilbertCurve(order=n)), run_time=5. / n)
Beispiel #23
0
 def __init__(self, pi_creature, **kwargs):
     start_state = pi_creature.copy()
     self.target_states = [
         pi_creature.copy().change_mode("wave_%d"%x)
         for x in 1, 2, 3
     ] + [
         pi_creature.copy()
     ]
     Transform.__init__(self, pi_creature, self.target_states[0], **kwargs)
Beispiel #24
0
    def construct(self, order):
        if order == 2:
            result_tex = "(0.125, 0.75)"
        elif order == 3:
            result_tex = "(0.0758,  0.6875)"

        phc, arg, result = TexMobject([
            "\\text{PHC}_%d"%order, 
            "(0.3)", 
            "= %s"%result_tex
        ]).to_edge(UP).split()
        function = TextMobject("Function", size = "\\normal")
        function.shift(phc.get_center()+DOWN+2*LEFT)
        function_arrow = Arrow(function, phc)

        line = Line(5*LEFT, 5*RIGHT)
        curve = HilbertCurve(order = order)
        line.match_colors(curve)
        grid = Grid(2**order, 2**order)
        grid.fade()
        for mob in curve, grid:
            mob.scale(0.7)
        index = int(0.3*line.get_num_points())
        dot1 = Dot(line.points[index])
        arrow1 = Arrow(arg, dot1, buff = 0.1)
        dot2 = Dot(curve.points[index])
        arrow2 = Arrow(result.get_bottom(), dot2, buff = 0.1)

        self.add(phc)
        self.play(
            ShimmerIn(function),
            ShowCreation(function_arrow)
        )
        self.wait()
        self.remove(function_arrow, function)
        self.play(ShowCreation(line))
        self.wait()
        self.play(
            ShimmerIn(arg),
            ShowCreation(arrow1),
            ShowCreation(dot1)
        )
        self.wait()
        self.remove(arrow1)
        self.play(
            FadeIn(grid),            
            Transform(line, curve),
            Transform(dot1, dot2),
            run_time = 2
        )
        self.wait()
        self.play(
            ShimmerIn(result),
            ShowCreation(arrow2)
        )
        self.wait()
Beispiel #25
0
 def update_mobject(self, alpha):
     scaled = alpha*len(self.target_states)
     try:
         if scaled-1 > 0:
             self.starting_mobject = self.target_states[int(scaled)-1]
         self.ending_mobject = self.target_states[int(scaled)]
     except IndexError:
         self.ending_mobject = self.target_states[-1]
     Transform.update_mobject(self, scaled%1)
     return self
Beispiel #26
0
    def zoom_in_on(self, number, zoom_factor, run_time=2.0):
        unit_length_to_spatial_width = self.number_line.unit_length_to_spatial_width * zoom_factor
        radius = SPACE_WIDTH / unit_length_to_spatial_width
        tick_frequency = 10**(np.floor(np.log10(radius)))
        left_tick = tick_frequency * (np.ceil(
            (number - radius) / tick_frequency))
        new_number_line = NumberLine(
            numerical_radius=radius,
            unit_length_to_spatial_width=unit_length_to_spatial_width,
            tick_frequency=tick_frequency,
            leftmost_tick=left_tick,
            number_at_center=number)
        new_displayed_numbers = new_number_line.default_numbers_to_display()
        new_number_mobs = new_number_line.get_number_mobjects(
            *new_displayed_numbers)

        transforms = []
        additional_mobjects = []
        squished_new_line = new_number_line.copy()
        squished_new_line.scale(1.0 / zoom_factor)
        squished_new_line.shift(self.number_line.number_to_point(number))
        squished_new_line.points[:, 1] = self.number_line.number_to_point(0)[1]
        transforms.append(Transform(squished_new_line, new_number_line))
        for mob, num in zip(new_number_mobs, new_displayed_numbers):
            point = Point(self.number_line.number_to_point(num))
            point.shift(new_number_line.get_vertical_number_offset())
            transforms.append(Transform(point, mob))
        for mob in self.mobjects:
            if mob == self.number_line:
                new_mob = mob.copy()
                new_mob.shift(-self.number_line.number_to_point(number))
                new_mob.stretch(zoom_factor, 0)
                transforms.append(Transform(mob, new_mob))
                continue
            mob_center = mob.get_center()
            number_under_center = self.number_line.point_to_number(mob_center)
            new_point = new_number_line.number_to_point(number_under_center)
            new_point += mob_center[1] * UP
            if mob in self.number_mobs:
                transforms.append(Transform(mob, Point(new_point)))
            else:
                transforms.append(
                    ApplyMethod(mob.shift, new_point - mob_center))
                additional_mobjects.append(mob)
        line_to_hide_pixelation = Line(self.number_line.get_left(),
                                       self.number_line.get_right(),
                                       color=self.number_line.get_color())
        self.add(line_to_hide_pixelation)
        self.play(*transforms, run_time=run_time)
        self.clear()
        self.number_line = new_number_line
        self.displayed_numbers = new_displayed_numbers
        self.number_mobs = new_number_mobs
        self.add(self.number_line, *self.number_mobs)
        self.add(*additional_mobjects)
Beispiel #27
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.wait()
        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.wait()

        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.wait()
Beispiel #28
0
    def construct(self, order):
        start_color, end_color = RED, GREEN
        curve = HilbertCurve(order = order)
        line = Line(5*LEFT, 5*RIGHT)
        for mob in curve, line:
            mob.gradient_highlight(start_color, end_color)
        freq_line = get_freq_line()
        freq_line.replace(line, stretch = True)

        unit = 6./(2**order) #sidelength of pixel
        up = unit*UP
        right = unit*RIGHT
        lower_left = 3*(LEFT+DOWN)
        squares = Mobject(*[
            Square(
                side_length = unit, 
                color = WHITE
            ).shift(x*right+y*up)
            for x, y in it.product(range(2**order), range(2**order))
        ])
        squares.center()
        targets = Mobject()
        for square in squares.submobjects:
            center = square.get_center()
            distances = np.apply_along_axis(
                lambda p : np.linalg.norm(p-center),
                1,
                curve.points
            )
            index_along_curve = np.argmin(distances)
            fraction_along_curve = index_along_curve/float(curve.get_num_points())
            target = square.copy().center().scale(0.8/(2**order))
            line_index = int(fraction_along_curve*line.get_num_points())
            target.shift(line.points[line_index])
            targets.add(target)


        self.add(squares)
        self.play(ShowCreation(
            curve,
            run_time = 5, 
            rate_func = None
        ))
        self.dither()
        self.play(
            Transform(curve, line),
            Transform(squares, targets),
            run_time = 3
        )
        self.dither()
        self.play(ShowCreation(freq_line))
        self.dither()
Beispiel #29
0
    def construct(self):
        mathy, bubble = get_mathy_and_bubble()
        squiggle_mouth = mathy.mouth.copy()
        squiggle_mouth.apply_function(
            lambda (x, y, z) : (x, y+0.02*np.sin(50*x), z)
        )
        bubble.ingest_submobjects()        
        bubble.write("Why not use a Hilbert curve \\textinterrobang ")
        words1 = bubble.content
        bubble.write("So, it's not one curve but an infinite family of curves \\dots")
        words2 = bubble.content
        bubble.write("Well, no, it \\emph{is} just one thing, but I need \\\\ \
                      to tell you about a certain infinite family first.")
        words3 =  bubble.content
        description = TextMobject("Mathematician friend", size = "\\small")
        description.next_to(mathy, buff = 2)
        arrow = Arrow(description, mathy)

        self.add(mathy)
        self.play(
            ShowCreation(arrow),
            ShimmerIn(description)
        )
        self.dither()
        point = Point(bubble.get_tip())
        self.play(
            Transform(point, bubble),
        )
        self.remove(point)
        self.add(bubble)
        self.play(ShimmerIn(words1))
        self.dither()
        self.remove(description, arrow)
        self.play(
            Transform(mathy.mouth, squiggle_mouth),
            ApplyMethod(mathy.arm.wag, 0.2*RIGHT, LEFT),
        )
        self.remove(words1)
        self.add(words2)
        self.dither(2)
        self.remove(words2)
        self.add(words3)
        self.dither(2)
        self.play(
            ApplyPointwiseFunction(
                lambda p : 15*p/np.linalg.norm(p),
                bubble
            ),
            ApplyMethod(mathy.shift, 5*(DOWN+LEFT)),
            FadeOut(words3),
            run_time = 3
        )
Beispiel #30
0
    def __init__(self, mobject_or_point, **kwargs):
        digest_config(self, kwargs)
        big_dot = Dot(
            radius=FRAME_X_RADIUS + FRAME_Y_RADIUS,
            stroke_width=0,
            fill_color=self.color,
            fill_opacity=0,
        )
        little_dot = Dot(radius=0)
        little_dot.set_fill(self.color, opacity=self.opacity)
        little_dot.move_to(mobject_or_point)

        Transform.__init__(self, big_dot, little_dot, **kwargs)
Beispiel #31
0
    def __init__(self, mobject_or_point, **kwargs):
        digest_config(self, kwargs)
        big_dot = Dot(
            radius=FRAME_X_RADIUS + FRAME_Y_RADIUS,
            stroke_width=0,
            fill_color=self.color,
            fill_opacity=0,
        )
        little_dot = Dot(radius=0)
        little_dot.set_fill(self.color, opacity=self.opacity)
        little_dot.move_to(mobject_or_point)

        Transform.__init__(self, big_dot, little_dot, **kwargs)
Beispiel #32
0
    def construct(self):
        grid = get_grid()
        grid.scale_to_fit_width(6)
        grid.to_edge(LEFT)
        freq_line = get_freq_line()
        freq_line.scale_to_fit_width(6)
        freq_line.center().to_edge(RIGHT)
        arrow =  Arrow(grid, freq_line)

        color1, color2 = YELLOW_C, RED
        square_length = 0.01
        dot1 = Dot(color = color1)
        dot1.shift(3*RIGHT)
        dot2 = Dot(color = color2)
        dot2.shift(3.1*RIGHT)
        arrow1 = Arrow(2*RIGHT+UP, dot1, color = color1, buff = 0.1)
        arrow2 = Arrow(4*RIGHT+UP, dot2, color = color2, buff = 0.1)
        dot3, arrow3 = [
            mob.copy().shift(5*LEFT+UP)
            for mob in dot1, arrow1
        ]
        dot4, arrow4 = [
            mob.copy().shift(5*LEFT+0.9*UP)
            for mob in dot2, arrow2
        ]

        self.add(grid, freq_line, arrow)
        self.dither()
        self.play(ApplyMethod(
            arrow.rotate, np.pi, 
            path_func = clockwise_path()
        ))
        self.dither()
        self.play(ShowCreation(arrow1))
        self.add(dot1)
        self.play(ShowCreation(arrow2))
        self.add(dot2)
        self.dither()
        self.remove(arrow1, arrow2)
        self.play(
            Transform(dot1, dot3),
            Transform(dot2, dot4)
        )
        self.play(
            ApplyMethod(grid.fade, 0.8),
            Animation(Mobject(dot3, dot4))
        )
        self.play(ShowCreation(arrow3))
        self.play(ShowCreation(arrow4))
        self.dither()
Beispiel #33
0
    def vector_to_coords(self, vector, integer_labels=True, clean_up=True):
        starting_mobjects = list(self.mobjects)
        show_creation = False
        if isinstance(vector, Arrow):
            arrow = vector
            vector = arrow.get_end()[:2]
        else:
            arrow = Vector(vector)
            show_creation = True
        array = vector_coordinate_label(arrow, integer_labels=integer_labels)
        x_line = Line(ORIGIN, vector[0] * RIGHT)
        y_line = Line(x_line.get_end(), arrow.get_end())
        x_line.set_color(X_COLOR)
        y_line.set_color(Y_COLOR)
        x_coord, y_coord = array.get_mob_matrix().flatten()
        x_coord_start = self.position_x_coordinate(
            x_coord.copy(), x_line, vector
        )
        y_coord_start = self.position_y_coordinate(
            y_coord.copy(), y_line, vector
        )
        brackets = array.get_brackets()

        if show_creation:
            self.play(ShowCreation(arrow))
        self.play(
            ShowCreation(x_line),
            Write(x_coord_start),
            run_time=1
        )
        self.play(
            ShowCreation(y_line),
            Write(y_coord_start),
            run_time=1
        )
        self.wait()
        self.play(
            Transform(x_coord_start, x_coord, submobject_mode="all_at_once"),
            Transform(y_coord_start, y_coord, submobject_mode="all_at_once"),
            Write(brackets, run_time=1),
        )
        self.wait()

        self.remove(x_coord_start, y_coord_start, brackets)
        self.add(array)
        if clean_up:
            self.clear()
            self.add(*starting_mobjects)
        return array, x_line, y_line
Beispiel #34
0
 def __init__(self, mobject, angle=np.pi, axis=OUT, **kwargs):
     if "path_arc" not in kwargs:
         kwargs["path_arc"] = angle
     if "path_arc_axis" not in kwargs:
         kwargs["path_arc_axis"] = axis
     digest_config(self, kwargs, locals())
     target = mobject.copy()
     if self.in_place:
         self.about_point = mobject.get_center()
     target.rotate(
         angle,
         axis=axis,
         about_point=self.about_point,
     )
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #35
0
 def clean_up(self, surrounding_scene=None):
     Transform.clean_up(self, surrounding_scene)
     self.update(0)
Beispiel #36
0
 def __init__(self, mobject, direction=DOWN, **kwargs):
     digest_config(self, kwargs)
     target = mobject.copy()
     mobject.shift(direction)
     mobject.fade(1)
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #37
0
 def __init__(self, mobject, **kwargs):
     Transform.__init__(
         self, mobject, mobject.get_point_mobject(), **kwargs
     )
Beispiel #38
0
 def __init__(self, mobject, **kwargs):
     digest_config(self, kwargs)
     target = mobject.copy()
     target.scale_in_place(self.scale_factor)
     target.set_color(self.color)
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #39
0
 def __init__(self, mobject, **kwargs):
     target = mobject.copy()
     target.fade(1)
     Transform.__init__(self, mobject, target, **kwargs)
Beispiel #40
0
 def __init__(self, mobject, **kwargs):
     mob_copy = mobject.copy()
     mob_copy.reverse_points()
     Transform.__init__(self, mobject, mob_copy, **kwargs)