Search code examples
pythonanimationmanimalgorithm-animation

How to create a table with empty cells?


When using Manim, how to create a table such that in the first row there are letters of the word "HELLO", and in the second row there are empty cells?

Python code:

t3 = Table(
    [["H", "E", "L", "L", "O"],
    [" ", " ", " ", " ", " "]], include_outer_lines=True,
    line_config={"stroke_width": 5, "color": BLUE}, v_buff = 1.3).scale(0.8)

self.play(FadeIn(t3, run_time=2))

My result:

enter image description here


Solution

  • A dirty trick would be to set the cells of the empty row the same as the one above, but also change its opacity to 0:

    Output

    from manim import *
    
    class EmptyTableCells(Scene):
        def construct(self):
    
          t = Table(
          [["H", "E", "L", "L", "O"],
          ["H", "E", "L", "L", "O"]], include_outer_lines=True,
          line_config={"stroke_width": 5, "color": BLUE}, v_buff = 1.3).scale(0.8)
    
          t.get_rows()[1].set_opacity(0) # change the second row's text opacity
          self.play(FadeIn(t, run_time=2))