Esempio n. 1
0
class GrowToOrder8PseudoHilbertCurve(Scene):
    def construct(self):
        self.curve = HilbertCurve(order=1)
        self.add(self.curve)
        self.wait()
        while self.curve.order < 8:
            self.increase_order()

    def increase_order(self):
        mini_curves = [
            self.curve.copy().scale(0.5).shift(1.5 * vect)
            for vect in [LEFT + DOWN, LEFT + UP, RIGHT + UP, RIGHT + DOWN]
        ]
        self.remove(self.curve)
        self.play(Transform(self.curve.copy(), mini_curves[0]))
        self.play(
            *[GrowFromCenter(mini_curve) for mini_curve in mini_curves[1:]])
        self.wait()
        self.clear()
        self.add(*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.curve = HilbertCurve(order=self.curve.order + 1)
        self.play(ShowCreation(self.curve, run_time=2))
        self.remove(*mini_curves)
        self.wait()
Esempio n. 2
0
 def construct(self):
     coords_set = [ORIGIN]
     for n in range(int(FRAME_WIDTH)):
         for vect in UP, RIGHT:
             for k in range(n):
                 new_coords = coords_set[-1]+((-1)**n)*vect
                 coords_set.append(new_coords)
     square = Square(side_length = 1, color = WHITE)
     squares = Mobject(*[
         square.copy().shift(coords)
         for coords in coords_set
     ]).ingest_submobjects()
     self.play(
         DelayByOrder(FadeIn(squares)),
         run_time = 3
     )
     curve = HilbertCurve(order = 6).scale(1./6)
     all_curves = Mobject(*[
         curve.copy().shift(coords)
         for coords in coords_set
     ]).ingest_submobjects()
     all_curves.thin_out(10)
     self.play(ShowCreation(
         all_curves,
         rate_func = None,
         run_time = 15
     ))
Esempio n. 3
0
    def construct(self):
        curve = HilbertCurve(order = 6)
        curve.set_color(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()
Esempio n. 4
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()
Esempio n. 5
0
 def construct(self):
     coords_set = [ORIGIN]
     for n in range(int(2*SPACE_WIDTH)):
         for vect in UP, RIGHT:
             for k in range(n):
                 new_coords = coords_set[-1]+((-1)**n)*vect
                 coords_set.append(new_coords)
     square = Square(side_length = 1, color = WHITE)
     squares = Mobject(*[
         square.copy().shift(coords)
         for coords in coords_set
     ]).ingest_submobjects()
     self.play(
         DelayByOrder(FadeIn(squares)),
         run_time = 3
     )
     curve = HilbertCurve(order = 6).scale(1./6)
     all_curves = Mobject(*[
         curve.copy().shift(coords)
         for coords in coords_set
     ]).ingest_submobjects()
     all_curves.thin_out(10)
     self.play(ShowCreation(
         all_curves,
         rate_func = None,
         run_time = 15
     ))
Esempio n. 6
0
class GrowToOrder8PseudoHilbertCurve(Scene):
    def construct(self):
        self.curve = HilbertCurve(order = 1)
        self.add(self.curve)
        self.dither()
        while self.curve.order < 8:
            self.increase_order()


    def increase_order(self):
        mini_curves = [
            self.curve.copy().scale(0.5).shift(1.5*vect)
            for vect in [
                LEFT+DOWN,
                LEFT+UP,
                RIGHT+UP,
                RIGHT+DOWN
            ]
        ]
        self.remove(self.curve)
        self.play(
            Transform(self.curve.copy(), mini_curves[0])
        )
        self.play(*[
            GrowFromCenter(mini_curve)
            for mini_curve in mini_curves[1:]
        ])
        self.dither()
        self.clear()
        self.add(*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.curve = HilbertCurve(order = self.curve.order+1)
        self.play(ShowCreation(self.curve, run_time = 2))
        self.remove(*mini_curves)
        self.dither()