Search code examples
manim

How to get current timestamp in runtime


There are three statements like below:

print("first time", time.time())
self.wait(5)
print("second time", time.time())

I suppose the difference between "second time" and "first time" will be 5 seconds, however, they are the same, why?

I think the self.wait(5) should be async call, if so, how to get timestame in runtime?


Solution

  • If what you want is to print in the terminal the exact second of each moment of the animation you can do something like this (the time is saved in the variable self.time):

    class TimeTest(Scene):
        def print_time(self):
            print("Time:",self.time)
    
        def construct(self):
            dot=Dot()
            # 0 seconds
            self.print_time()
            self.play(Write(dot,run_time=2))
            # 2 seconds
            self.print_time()
            self.wait()
            # 3 seconds
            self.print_time()
            self.play(dot.shift,UP,run_time=1)
            # 4 seconds
            self.print_time()
            self.play(FadeToColor(dot,RED,run_time=3))
            # 7 seconds
            self.print_time()
            self.wait()
            # 8 seconds
            self.print_time()