我不想使用 Manim 创建一个小动画。有一个矩形,将在其中绘制两条线(在矩形的左侧和底部),并且一个新的矩形应该从底部“生长”。使用GrowFromEdge(element, DOWN)
矩形的宽度也会改变,但只有高度应该改变。我该怎么办?使用height=0
然后ApplyMethod(element.set_height, HEIGHT)
不显示任何内容。这是我的代码:
from manimlib.imports import *
from manimlib.constants import COLOR_MAP
import numpy as np
class Test(Scene):
def construct(self):
EXPLAIN_WIDTH = 5
EXPLAIN_HEIGHT = 2
explain_rect = Rectangle(
width=EXPLAIN_WIDTH,
height=EXPLAIN_HEIGHT,
origin=np.array(
[0,
0,
0]
)
).set_stroke(width=1)
explain_line_left = Line(
start=np.array(
[EXPLAIN_WIDTH / -2,
EXPLAIN_HEIGHT / -2,
0]
),
end=np.array(
[EXPLAIN_WIDTH / -2,
EXPLAIN_HEIGHT / 2,
0]
),
).set_color(COLOR_MAP["RED_A"])
explain_line_bottom = Line(
start=np.array(
[EXPLAIN_WIDTH / -2,
EXPLAIN_HEIGHT / -2,
0]
),
end=np.array(
[EXPLAIN_WIDTH / 2,
EXPLAIN_HEIGHT / -2,
0]
),
color=COLOR_MAP["RED_A"]
)
explain_filled_rect = Rectangle(
width=EXPLAIN_WIDTH,
height=EXPLAIN_HEIGHT,
color=None
).set_fill(COLOR_MAP["RED_A"], 1)
self.play(FadeIn(explain_rect))
self.play(
GrowFromEdge(explain_line_left, BOTTOM),
GrowFromEdge(explain_line_bottom, LEFT)
)
self.wait(1)
self.play(GrowFromEdge(explain_filled_rect, BOTTOM))
self.wait(2)