Manim: Table as place holder

When using a compound object, it is not necessary to create it all together. You can also decide to create the parts one at a time, and not create all of them.

In a video about numbering systems I needed to place numbers in a table, show one row at a time (one of them from right to left), and show only one of the inner rows of the table.

Manim: Table as place holder
class TableAsPlaceHolder(Scene):

    def construct(self):

        number = MathTex("100010_2 =~?_{10}").scale(2).to_edge(UP)
        self.play(Write(number))

        table = MathTable(
            [[1, 0, 0, 0, 1, 0],
            [32, 16, 8, 4, 2, 1],
            [32, 0, 0, 0, 2, 0]]
        )
        
        self.play(Write(table.get_rows()[0]))
        
        self.play(Write(VGroup(*reversed(table.get_rows()[1]))))

        self.play(Create(table.get_horizontal_lines()[1]))
        
        arrow = Arrow(
            start = table.get_cell((1, 1)).get_left(), 
            end = table.get_cell((1, 1)).get_left()
        ).shift(.5*LEFT)
        arrow.target = Arrow(
            start = table.get_cell((1, 1)).get_left(), 
            end = table.get_cell((3, 1)).get_left()
        ).shift(.5*LEFT)
        
        times = MathTex(r"\times").move_to(arrow, LEFT).shift(.5 * LEFT)
        times.add_updater(
            lambda x: x.move_to(arrow, LEFT).shift(.5 * LEFT)
        )

        self.add(arrow)
        self.add(times)
        self.play(MoveToTarget(arrow))
        
        self.play(Write(table.get_rows()[2]))
            
        self.play(FadeOut(VGroup(times, arrow)))

        arrow = Arrow(
            start = table.get_cell((3, 1)).get_bottom(), 
            end = table.get_cell((3, 1)).get_bottom()
        ).shift(.1 * DOWN)
        arrow.target = Arrow(
            start = table.get_cell((3, 1)).get_bottom(), 
            end = table.get_cell((3, 6)).get_bottom()
        ).shift(.1*DOWN)
        
        add = MathTex("+").move_to(arrow, DOWN).shift(.3*DOWN)
        add.add_updater(
            lambda x: x.move_to(arrow, DOWN).shift(.3*DOWN)
        )
        
        self.add(arrow)
        self.add(add)
        self.play(MoveToTarget(arrow))

        self.play(Write(MathTex("= 34_{10}").scale(2).to_edge(DOWN)))
        
        self.play(FadeOut(VGroup(arrow, add)))
        self.wait(5)

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *