Exemplo n.º 1
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
     ))
Exemplo n.º 2
0
    def generate_points(self):
        for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
            face = Square(side_length = self.side_length)
            face.shift(self.side_length*OUT/2.0)
            face.apply_function(lambda p : np.dot(p, z_to_vector(vect).T))

            self.add(face)
Exemplo n.º 3
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()
Exemplo n.º 4
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_sub_mobjects()
     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_sub_mobjects()
     all_curves.thin_out(10)
     self.play(ShowCreation(
         all_curves,
         rate_func = None,
         run_time = 15
     ))
Exemplo n.º 5
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))
Exemplo n.º 6
0
 def generate_points(self):
     faces = [
         Square(side_length=self.side_length).shift(OUT).apply_function(
             lambda p: np.dot(p,
                              z_to_vector(vect).T))
         for vect in IN, OUT, LEFT, RIGHT, UP, DOWN
     ]
     self.add(*faces)
Exemplo n.º 7
0
    def scroll_through_patrons(self):
        logo_box = Square(side_length=2.5)
        logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF)
        total_width = SPACE_WIDTH - logo_box.get_right()[0]

        black_rect = Rectangle(fill_color=BLACK,
                               fill_opacity=1,
                               stroke_width=0,
                               width=2 * SPACE_WIDTH,
                               height=1.1 * SPACE_HEIGHT)
        black_rect.to_edge(UP, buff=0)
        line = DashedLine(SPACE_WIDTH * LEFT, SPACE_WIDTH * RIGHT)
        line.move_to(black_rect, DOWN)
        line.shift(SMALL_BUFF * SMALL_BUFF * DOWN)
        self.add(line)

        patrons = VGroup(*map(TextMobject, self.specific_patrons))
        patrons.scale(self.patron_scale_val)
        for patron in patrons:
            if patron.get_width() > self.max_patron_width:
                patron.scale_to_fit_width(self.max_patron_width)
        columns = VGroup(*[
            VGroup(*patrons[i::self.n_patron_columns]).arrange_submobjects(
                DOWN, buff=MED_SMALL_BUFF)
            for i in range(self.n_patron_columns)
        ])
        columns.arrange_submobjects(
            RIGHT,
            buff=LARGE_BUFF,
            aligned_edge=UP,
        )
        columns.scale_to_fit_width(total_width - 1)
        columns.next_to(black_rect, DOWN, 3 * LARGE_BUFF)
        columns.to_edge(RIGHT)

        self.play(
            columns.next_to,
            SPACE_HEIGHT * DOWN,
            UP,
            LARGE_BUFF,
            columns.to_edge,
            RIGHT,
            Animation(black_rect),
            rate_func=None,
            run_time=self.run_time,
        )
Exemplo n.º 8
0
    def generate_points(self):
        body = Cube(side_length = 1)
        for dim, scale_factor in enumerate(self.body_dimensions):
            body.stretch(scale_factor, dim = dim)
        body.scale_to_fit_width(self.width)
        body.set_fill(self.shaded_body_color, opacity = 1)
        body.sort_submobjects(lambda p : p[2])
        body[-1].set_fill(self.body_color)
        keyboard = VGroup(*[
            VGroup(*[
                Square(**self.key_color_kwargs)
                for x in range(12-y%2)
            ]).arrange_submobjects(RIGHT, buff = SMALL_BUFF)
            for y in range(4)
        ]).arrange_submobjects(DOWN, buff = MED_SMALL_BUFF)
        keyboard.stretch_to_fit_width(
            self.keyboard_width_to_body_width*body.get_width(),
        )
        keyboard.stretch_to_fit_height(
            self.keyboard_height_to_body_height*body.get_height(),
        )
        keyboard.next_to(body, OUT, buff = 0.1*SMALL_BUFF)
        keyboard.shift(MED_SMALL_BUFF*UP)
        body.add(keyboard)

        screen_plate = body.copy()
        screen_plate.stretch(self.screen_thickness/self.body_dimensions[2], dim = 2)
        screen = Rectangle(
            stroke_width = 0,
            fill_color = BLACK,
            fill_opacity = 1,
        )
        screen.replace(screen_plate, stretch = True)
        screen.scale_in_place(self.screen_width_to_screen_plate_width)
        screen.next_to(screen_plate, OUT, buff = 0.1*SMALL_BUFF)
        screen_plate.add(screen)
        screen_plate.next_to(body, UP, buff = 0)
        screen_plate.rotate(
            self.open_angle, RIGHT, 
            about_point = screen_plate.get_bottom()
        )
        self.screen_plate = screen_plate
        self.screen = screen

        axis = Line(
            body.get_corner(UP+LEFT+OUT),
            body.get_corner(UP+RIGHT+OUT),
            color = BLACK,
            stroke_width = 2
        )
        self.axis = axis

        self.add(body, screen_plate, axis)
        self.rotate(5*np.pi/12, LEFT)
        self.rotate(np.pi/6, DOWN)
Exemplo n.º 9
0
    def generate_points(self):
        for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
            face = Square(side_length=self.side_length)
            face.shift(self.side_length * OUT / 2.0)
            face.apply_function(lambda p: np.dot(p, z_to_vector(vect).T))

            self.add(face)
Exemplo n.º 10
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()
Exemplo n.º 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()
Exemplo n.º 12
0
 def add_unit_square(self, color=YELLOW, opacity=0.3, animate=False):
     square = Square(color=color, side_length=1)
     square.shift(-square.get_corner(DOWN + LEFT))
     if animate:
         added_anims = map(Animation, self.moving_vectors)
         self.play(ShowCreation(square), *added_anims)
         self.play(square.set_fill, color, opacity, *added_anims)
     else:
         square.set_fill(color, opacity)
     self.add_transformable_mobject(square)
     self.bring_to_front(*self.moving_vectors)
     self.square = square
     return self
Exemplo n.º 13
0
 def add_unit_square(self, color = YELLOW, opacity = 0.3, animate = False):
     square = Square(color = color, side_length = 1)
     square.shift(-square.get_corner(DOWN+LEFT))
     if animate:
         added_anims = map(Animation, self.moving_vectors)
         self.play(ShowCreation(square), *added_anims)
         self.play(square.set_fill, color, opacity, *added_anims)
     else:
         square.set_fill(color, opacity)
     self.add_transformable_mobject(square)
     self.bring_to_front(*self.moving_vectors)        
     self.square = square
     return self
Exemplo n.º 14
0
    def construct(self):
        time_line = get_time_line()
        time_line.shift(-time_line.number_to_point(1900))
        hilbert_curve = HilbertCurve(order = 3)
        peano_curve = PeanoCurve(order = 2)
        for curve in hilbert_curve, peano_curve:
            curve.scale(0.5)
        hilbert_curve.to_corner(DOWN+RIGHT)
        peano_curve.to_corner(UP+LEFT)
        squares = Mobject(*[
            Square(side_length=3, color=WHITE).replace(curve)
            for curve in hilbert_curve, peano_curve
        ])


        self.add(time_line)
        self.wait()
        for year, curve, vect, text in [
            (1890, peano_curve, UP, "Peano Curve"), 
            (1891, hilbert_curve, DOWN, "Hilbert Curve"),
            ]:
            point = time_line.number_to_point(year)
            point[1] = 0.2
            arrow = Arrow(point+2*vect, point, buff = 0.1)
            arrow.gradient_highlight(curve.start_color, curve.end_color)
            year_mob = TexMobject(str(year))
            year_mob.next_to(arrow, vect)
            words = TextMobject(text)
            words.next_to(year_mob, vect)

            self.play(
                ShowCreation(arrow), 
                ShimmerIn(year_mob),
                ShimmerIn(words)
            )
            self.play(ShowCreation(curve))
            self.wait()
        self.play(ShowCreation(squares))
        self.wait()
        self.play(ApplyMethod(
            Mobject(*self.mobjects).shift, 20*(DOWN+RIGHT)
        ))