如何在特定位置开始写入文字?

des*_*dos 2 manim

我在 Manim Community v0.16.0.post0 中有以下文本:

dioscuri = Text("DIOSCURI", weight=BOLD, font="Arial", color=BLACK)
self.play(Write(dioscuri))
Run Code Online (Sandbox Code Playgroud)

我希望使用 Write 方法写入文本,例如,在左上角而不是默认情况下在场景的中心。换句话说,如何在特定位置启动文字书写动画?

Add*_*dem 5

如果您特别希望文本位于左上角位置,那么实现此目的的一个很好的简单方法是

# Send to the upper-left corner.
dioscuri = Text("DIOSCURI", weight=BOLD, font="Arial", color=BLACK).to_edge(UL) 
self.play(Write(dioscuri))
Run Code Online (Sandbox Code Playgroud)

如果你想给出坐标,你可以这样做

# Place it at coordinates (x,y) measured from the center of the screen.
dioscuri = Text("DIOSCURI", weight=BOLD, font="Arial", color=BLACK).move_to([x,y,0])
self.play(Write(dioscuri))
Run Code Online (Sandbox Code Playgroud)

或者,如果指定坐标的其他方式更有意义,您也可以将其放置在一个角落,然后将其移动一个移位向量。

# Send to the lower-right corner, then shift by vector (x,y).
dioscuri = Text("DIOSCURI", weight=BOLD, font="Arial", color=BLACK).to_edge(DR).shift([x,y,0])
self.play(Write(dioscuri))
Run Code Online (Sandbox Code Playgroud)