Пример #1
0
    def construct(self):
        words = TextMobject("Order 3 Pseudo-Hilbert Curve")
        words.highlight(GREEN)
        words.to_edge(UP)
        grid4 = Mobject(Grid(2, 2), Grid(4, 4, point_thickness=2))
        grid8 = Grid(8, 8, point_thickness=1)
        order_3_curve = HilbertCurve(order=3)
        mini_curves = [
            HilbertCurve(order=2).scale(0.5).shift(1.5 * vect)
            for vect in [LEFT + DOWN, LEFT + UP, RIGHT + UP, RIGHT + DOWN]
        ]

        self.add(words, grid4)
        self.dither()
        self.play(ShowCreation(grid8))
        self.dither()
        self.play(*map(GrowFromCenter, mini_curves))
        self.dither()
        self.clear()
        self.add(words, grid8, *mini_curves)
        self.play(*[
            ApplyMethod(curve.rotate_in_place, np.pi, axis)
            for curve, axis in [(mini_curves[0],
                                 UP + RIGHT), (mini_curves[3], UP + LEFT)]
        ])
        self.play(ShowCreation(order_3_curve, run_time=5))
        self.dither()
Пример #2
0
    def construct(self):
        words, s = TextMobject(["Pseudo-Hilbert Curve", "s"]).split()
        pre_words = TextMobject("Order 1")
        pre_words.next_to(words, LEFT, buff = 0.5)
        s.next_to(words, RIGHT, buff = 0.05, aligned_edge = DOWN)
        cluster = Mobject(pre_words, words, s)
        cluster.center()
        cluster.scale(0.7)
        cluster.to_edge(UP, buff = 0.3)
        cluster.highlight(GREEN)
        grid1 = Grid(1, 1)
        grid2 = Grid(2, 2)
        curve = HilbertCurve(order = 1)

        self.add(words, s)
        self.dither()
        self.play(Transform(
            s, pre_words, 
            path_func = path_along_arc(-np.pi/3)
        ))
        self.dither()
        self.play(ShowCreation(grid1))
        self.dither()
        self.play(ShowCreation(grid2))
        self.dither()
        kwargs = {
            "run_time" : 5,
            "rate_func" : None
        }
        self.play(ShowCreation(curve, **kwargs))
        self.dither()
Пример #3
0
    def construct(self):
        scale_factor = 0.9
        grid = Grid(4, 4, stroke_width=1)
        curve = HilbertCurve(order=2)
        for mob in grid, curve:
            mob.scale(scale_factor)
        words = TextMobject("""
            Sequence of curves is stable 
            $\\leftrightarrow$ existence of limit curve
        """,
                            size="\\normal")
        words.scale(1.25)
        words.to_edge(UP)

        self.add(curve, grid)
        self.wait()
        for n in range(3, 7):
            if n == 5:
                self.play(ShimmerIn(words))
            new_grid = Grid(2**n, 2**n, stroke_width=1)
            new_curve = HilbertCurve(order=n)
            for mob in new_grid, new_curve:
                mob.scale(scale_factor)
            self.play(ShowCreation(new_grid), Animation(curve))
            self.remove(grid)
            grid = new_grid
            self.play(Transform(curve, new_curve))
            self.wait()
Пример #4
0
    def construct(self):
        words = TextMobject("Order 2 Pseudo-Hilbert Curve")
        words.to_edge(UP, buff=0.3)
        words.highlight(GREEN)
        grid2 = Grid(2, 2)
        grid4 = Grid(4, 4, point_thickness=2)
        # order_1_curve = HilbertCurve(order = 1)
        # squaggle_curve = order_1_curve.copy().apply_function(
        #     lambda (x, y, z) : (x + np.cos(3*y), y + np.sin(3*x), z)
        # )
        # squaggle_curve.show()
        mini_curves = [
            HilbertCurve(order=1).scale(0.5).shift(1.5 * vect)
            for vect in [LEFT + DOWN, LEFT + UP, RIGHT + UP, RIGHT + DOWN]
        ]
        last_curve = mini_curves[0]
        naive_curve = Mobject(last_curve)
        for mini_curve in mini_curves[1:]:
            line = Line(last_curve.points[-1], mini_curve.points[0])
            naive_curve.add(line, mini_curve)
            last_curve = mini_curve
        naive_curve.ingest_sub_mobjects()
        naive_curve.gradient_highlight(RED, GREEN)
        order_2_curve = HilbertCurve(order=2)

        self.add(words, grid2)
        self.dither()
        self.play(ShowCreation(grid4))
        self.play(*[ShowCreation(mini_curve) for mini_curve in mini_curves])
        self.dither()
        self.play(ShowCreation(naive_curve, run_time=5))
        self.remove(*mini_curves)
        self.dither()
        self.play(Transform(naive_curve, order_2_curve))
        self.dither()
Пример #5
0
    def construct(self):
        words = TextMobject([
            "One does not simply define the limit \\\\ \
            of a sequence of", "curves", "\\dots"
        ])
        top_words = TextMobject(["curves", "are functions"]).to_edge(UP)
        curves1 = words.split()[1]
        curves2 = top_words.split()[0]
        words.ingest_submobjects()
        number = TexMobject("0.27")
        pair = TexMobject("(0.53, 0.02)")
        pair.next_to(number, buff=2)
        arrow = Arrow(number, pair)
        Mobject(number, arrow, pair).center().shift(UP)
        number_line = UnitInterval()
        number_line.stretch_to_fit_width(5)
        number_line.to_edge(LEFT).shift(DOWN)
        grid = Grid(4, 4).scale(0.4)
        grid.next_to(number_line, buff=2)
        low_arrow = Arrow(number_line, grid)

        self.play(ShimmerIn(words))
        self.dither()
        self.play(FadeOut(words), ApplyMethod(curves1.replace, curves2),
                  ShimmerIn(top_words.split()[1]))
        self.dither()
        self.play(FadeIn(number))
        self.play(ShowCreation(arrow))
        self.play(FadeIn(pair))
        self.dither()
        self.play(ShowCreation(number_line))
        self.play(ShowCreation(low_arrow))
        self.play(ShowCreation(grid))
        self.dither()
Пример #6
0
    def construct(self):
        curve = HilbertCurve(order=1)
        grid = Grid(2, 2, stroke_width=1)
        self.add(grid, curve)
        for order in range(2, 6):
            self.dither()
            new_grid = Grid(2**order, 2**order, stroke_width=1)
            self.play(ShowCreation(new_grid), Animation(curve))
            self.remove(grid)
            grid = new_grid
            self.play(Transform(curve, HilbertCurve(order=order)))

        square = Square(side_length=6, color=WHITE)
        square.corner = Mobject1D()
        square.corner.add_line(3 * DOWN, ORIGIN)
        square.corner.add_line(ORIGIN, 3 * RIGHT)
        square.digest_mobject_attrs()
        square.scale(2**(-5))
        square.corner.highlight(
            Color(rgb=curve.rgbs[curve.get_num_points() / 3]))
        square.shift(
            grid.get_corner(UP+LEFT)-\
            square.get_corner(UP+LEFT)
        )

        self.dither()
        self.play(FadeOut(grid), FadeOut(curve), FadeIn(square))
        self.play(ApplyMethod(square.replace, grid))
        self.dither()
Пример #7
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()
Пример #8
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.dither()
        self.remove(function_arrow, function)
        self.play(ShowCreation(line))
        self.dither()
        self.play(
            ShimmerIn(arg),
            ShowCreation(arrow1),
            ShowCreation(dot1)
        )
        self.dither()
        self.remove(arrow1)
        self.play(
            FadeIn(grid),            
            Transform(line, curve),
            Transform(dot1, dot2),
            run_time = 2
        )
        self.dither()
        self.play(
            ShimmerIn(result),
            ShowCreation(arrow2)
        )
        self.dither()
Пример #9
0
    def construct(self):
        big_grid_dim = 20.
        small_grid_dim = 6.
        big_grid = Grid(64, 64, height=big_grid_dim, width=big_grid_dim)
        big_grid.to_corner(UP + RIGHT, buff=2)
        small_grid = big_grid.copy()
        small_grid.scale(small_grid_dim / big_grid_dim)
        small_grid.center()
        pixel = MobjectFromRegion(
            region_from_polygon_vertices(
                *0.2 *
                np.array([RIGHT + DOWN, RIGHT + UP, LEFT + UP, LEFT + DOWN])))
        pixel.set_color(WHITE)
        pixel_width = big_grid.width / big_grid.columns
        pixel.scale_to_fit_width(pixel_width)
        pixel.to_corner(UP + RIGHT, buff=2)
        pixel.shift(5 * pixel_width * (2 * LEFT + DOWN))

        freq_line = get_freq_line()
        dot = Dot()
        dot.shift(freq_line.get_center() + 2 * RIGHT)
        string = Line(LEFT, RIGHT, color=GREEN)
        arrow = Arrow(dot, string.get_center())
        vibration_config = {
            "overtones": 1,
            "spatial_period": 2,
        }
        vibration, loud_vibration, quiet_vibration = [
            Vibrate(string.copy(), amplitude=a, **vibration_config)
            for a in [0.5, 1., 0.25]
        ]

        self.add(small_grid)
        self.dither()
        self.play(Transform(small_grid, big_grid))
        self.play(FadeIn(pixel))
        self.dither()
        self.play(FadeOut(small_grid), ShowCreation(freq_line))
        self.remove(small_grid)
        self.play(Transform(pixel, dot), )
        self.dither()
        self.play(ShowCreation(arrow))
        self.play(loud_vibration)
        self.play(TransformAnimations(loud_vibration, quiet_vibration),
                  ApplyMethod(dot.fade, 0.9))
        self.clear()
        self.add(freq_line, dot, arrow)
        self.play(quiet_vibration)
Пример #10
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()
Пример #11
0
    def construct(self):
        curve = HilbertCurve(order = 1)
        grid = Grid(2, 2, point_thickness=1)
        self.add(grid, curve)
        for order in range(2, 6):
            self.dither()
            new_grid = Grid(2**order, 2**order, point_thickness=1)
            self.play(
                ShowCreation(new_grid),
                Animation(curve)          
            )
            self.remove(grid)
            grid = new_grid
            self.play(Transform(
                curve, HilbertCurve(order = order)
            ))


        square = Square(side_length = 6, color = WHITE)
        square.corner = Mobject1D()
        square.corner.add_line(3*DOWN, ORIGIN)
        square.corner.add_line(ORIGIN, 3*RIGHT)
        square.digest_mobject_attrs()
        square.scale(2**(-5))
        square.corner.highlight(
            Color(rgb = curve.rgbs[curve.get_num_points()/3])
        )
        square.shift(
            grid.get_corner(UP+LEFT)-\
            square.get_corner(UP+LEFT)
        )


        self.dither()
        self.play(
            FadeOut(grid), 
            FadeOut(curve),
            FadeIn(square)
        )
        self.play(
            ApplyMethod(square.replace, grid)
        )
        self.dither()
Пример #12
0
    def construct(self):
        grid = Grid(16, 16).fade()
        snake_curve = SnakeCurve(order=4)
        words = TextMobject("``Snake Curve''")
        words.next_to(grid, UP)

        self.add(grid)
        self.play(ShowCreation(snake_curve, run_time=7, rate_func=None))
        self.dither()
        self.play(ShimmerIn(words))
        self.dither()
Пример #13
0
    def construct(self):
        words = TextMobject(
            ["One does not simply define the limit \\\\ \
            of a sequence of","curves","\\dots"]
        )
        top_words = TextMobject([
            "curves", "are functions"
        ]).to_edge(UP)
        curves1 = words.split()[1]
        curves2 = top_words.split()[0]
        words.ingest_sub_mobjects()
        number = TexMobject("0.27")
        pair = TexMobject("(0.53, 0.02)")
        pair.next_to(number, buff = 2)
        arrow = Arrow(number, pair)
        Mobject(number, arrow, pair).center().shift(UP)
        number_line = UnitInterval()
        number_line.stretch_to_fit_width(5)
        number_line.to_edge(LEFT).shift(DOWN)
        grid = Grid(4, 4).scale(0.4)
        grid.next_to(number_line, buff = 2)
        low_arrow = Arrow(number_line, grid)

        self.play(ShimmerIn(words))
        self.dither()
        self.play(
            FadeOut(words),
            ApplyMethod(curves1.replace, curves2),
            ShimmerIn(top_words.split()[1])
        )
        self.dither()
        self.play(FadeIn(number))
        self.play(ShowCreation(arrow))
        self.play(FadeIn(pair))
        self.dither()
        self.play(ShowCreation(number_line))
        self.play(ShowCreation(low_arrow))
        self.play(ShowCreation(grid))
        self.dither()
Пример #14
0
    def construct(self):
        grid = Grid(64, 64)
        space_region = Region()
        space_mobject = MobjectFromRegion(space_region, DARK_GREY)
        curve = PeanoCurve(order = 5).replace(space_mobject)
        line = Line(5*LEFT, 5*RIGHT)
        line.gradient_highlight(curve.start_color, curve.end_color)
        for mob in grid, space_mobject:
            mob.sort_points(np.linalg.norm)
        infinitely = TextMobject("Infinitely")
        detailed = TextMobject("detailed")
        extending = TextMobject("extending")
        detailed.next_to(infinitely, RIGHT)
        extending.next_to(infinitely, RIGHT)
        Mobject(extending, infinitely, detailed).center()
        arrows = Mobject(*[
            Arrow(2*p, 4*p)
            for theta in np.arange(np.pi/6, 2*np.pi, np.pi/3)
            for p in [rotate_vector(RIGHT, theta)]
        ])

        self.add(grid)
        self.wait()
        self.play(Transform(grid, space_mobject, run_time = 5))
        self.remove(grid)
        self.highlight_region(space_region, DARK_GREY)
        self.wait()
        self.add(infinitely, detailed)
        self.wait()
        self.play(DelayByOrder(Transform(detailed, extending)))
        self.play(ShowCreation(arrows))
        self.wait()
        self.clear()
        self.highlight_region(space_region, DARK_GREY)
        self.play(ShowCreation(line))
        self.play(Transform(line, curve, run_time = 5))
Пример #15
0
def get_grid():
    return Grid(64, 64)
Пример #16
0
    def construct(self):
        big_grid_dim = 20.
        small_grid_dim = 6.
        big_grid = Grid(64, 64, height = big_grid_dim, width = big_grid_dim)
        big_grid.to_corner(UP+RIGHT, buff = 2)
        small_grid = big_grid.copy()
        small_grid.scale(small_grid_dim/big_grid_dim)
        small_grid.center()
        pixel = MobjectFromRegion(
            region_from_polygon_vertices(*0.2*np.array([
                RIGHT+DOWN,
                RIGHT+UP,
                LEFT+UP,
                LEFT+DOWN
            ]))
        )
        pixel.set_color(WHITE)
        pixel_width = big_grid.width/big_grid.columns
        pixel.scale_to_fit_width(pixel_width)
        pixel.to_corner(UP+RIGHT, buff = 2)
        pixel.shift(5*pixel_width*(2*LEFT+DOWN))

        freq_line = get_freq_line()
        dot = Dot()
        dot.shift(freq_line.get_center() + 2*RIGHT)
        string = Line(LEFT, RIGHT, color = GREEN)
        arrow = Arrow(dot, string.get_center())
        vibration_config = {
            "overtones"      : 1,
            "spatial_period" : 2,
        }
        vibration, loud_vibration, quiet_vibration = [
            Vibrate(string.copy(), amplitude = a, **vibration_config)
            for a in [0.5, 1., 0.25]
        ]

        self.add(small_grid)
        self.dither()
        self.play(
            Transform(small_grid, big_grid)
        )
        self.play(FadeIn(pixel))
        self.dither()
        self.play(
            FadeOut(small_grid),            
            ShowCreation(freq_line)
        )
        self.remove(small_grid)
        self.play(
            Transform(pixel, dot),
        )
        self.dither()
        self.play(ShowCreation(arrow))
        self.play(loud_vibration)
        self.play(
            TransformAnimations(loud_vibration, quiet_vibration),            
            ApplyMethod(dot.fade, 0.9)
        )
        self.clear()
        self.add(freq_line, dot, arrow)
        self.play(quiet_vibration)