定位Mobject
接下来,让我们回顾一下定位Mobject
的一些基本技巧。
打开
scene.py
,并在SquareToCircle
方法下方添加以下代码片段:
class SquareAndCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the color and transparency
square = Square() # create a square
square.set_fill(BLUE, opacity=0.5) # set the color and transparency
square.next_to(circle, RIGHT, buff=0.5) # set the position
self.play(Create(circle), Create(square)) # show the shapes on screen
通过在命令行中运行以下命令进行渲染
SquareAndCircle
:
manim -pql scene.py SquareAndCircle
next_to
是一种定位Mobject
的方法。
我们首先指定了 粉红色圆圈作为正方形的参考点,circle
作为方法的第一个参数Mobject
传递。 第二个参数用于指定相对于参考点的放置方向。 在本例中,我们将 direction 设置为 RIGHT
,告诉 Manim 将正方形定位在圆的右侧。 最后,在两个对象之间应用一个小的距离缓冲区buff=0.5
。
尝试更改RIGHT
为LEFT
、 UP
或DOWN
,看看它如何改变正方形的位置。
使用定位方法,可以渲染具有多个Mobject
的场景, 使用坐标设置它们在场景中的位置或定位它们相对于彼此。
Last updated