Search code examples
manim

How to start writing text at specific position?


I have the following text in Manim Community v0.16.0.post0:

dioscuri = Text("DIOSCURI", weight=BOLD, font="Arial", color=BLACK)
self.play(Write(dioscuri))

I would like the text to be written using the Write method, for example, in the upper left corner and not in the center of the scene as by default. In other words, how do I start the text-writing animation at a specific position?


Solution

  • If you specifically want the text in the upper-left position, then a nice simple way to accomplish this is

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

    If you want to give coordinates you can do this with

    # 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))
    

    Alternately you can place it in a corner and then shift it by a shift vector, if some other way of specifying coordinates makes more sense.

    # 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))