Manim 展示乳胶桌

问题描述

有没有办法使用 manim显示和制作乳胶桌?

例如

\begin{table}[]
\centering
\begin{tabular}{lllll}
 &  & \multicolumn{2}{l}{End} &  \\
Top &  & Bottom & Bottom &  \\
 & Top & 40 & 160 & 200 \\
 & Bottom & 640 & 160 & 800 \\
 &  & 200 & 800 & 1000
\end{tabular}
\end{table}

您在manim会怎样?

from manimlib import *
import numpy as np

class TableManim(Scene):
     def construct(self):
     ...

解决方法

如果你想直接用 LaTeX 来做它会是这样的:

class Table1(Scene):
    def construct(self):
        table = r"""
        \begin{table}[]
        \centering
        \begin{tabular}{|l|l|l|l|l|}\hline
        &  & \multicolumn{2}{l}{End} &  \\\hline
        Top &  & Bottom & Bottom &  \\
        & Top & 40 & 160 & 200 \\
        & Bottom & 640 & 160 & 800 \\
        &  & 200 & 800 & 1000 \\\hline
        \end{tabular}
        \end{table}
        """
        tex_table = TexText(table)
        self.play(Write(tex_table))

enter image description here

但是,如果你想用 Manim 制作一个表格,它会有点复杂,它会是这样的(如果你需要它,你可以转换成一个函数)

class Table2(Scene):
    def construct(self):
        table = VGroup(*[
            VGroup(*[
                Text(f"{t}")
                for t in row
            ]).arrange(DOWN,aligned_edge=LEFT)
            for row in [
                ["Top"],["Top","Bottom"],["Bottom",40,640,200],160,800],[200,800,1000],]],)
        table.scale(0.8)
        BUFF = 0.5
        rectangles = VGroup(*[
            Rectangle(
                width=mob.get_width()+BUFF,height=max(*[t.get_height() for t in table])+BUFF,).move_to(mob)
            for mob in table
        ])
        for t,r,align_direction in zip(table,rectangles,[UP,None,DOWN]):
            if align_direction is not None:
                t.align_to(r,align_direction)
                t.shift(-align_direction*BUFF/2)
        table_group = VGroup(*[
            VGroup(t,r)
            for t,r in zip(table,rectangles)
        ])
        table_group.arrange(RIGHT,buff=0)
        self.add(table_group)

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...