Updaters are not updated correctly on the first / last frames of animations.
In the below code sample, the red dot is expected to continuously move rightwards every frame: however, after the first animation, a frame is duplicated.
(The updater seems to be run twice between these two frames, but both with dt=0.)
Expected behavior
The updater should be run with dt=1/framerate, exactly once.
How to reproduce the issue
class Minimum(Scene):
def construct(self):
d = Dot(color=RED).move_to(UP)
d.add_updater(lambda d,dt: d.set_x(d.get_x()+dt))
def updater(d,dt):
d.set_x(d.get_x()+dt)
print(dt) # prints 0 at the end of first / beginning of second animation
d.add_updater(updater)
e,f = Dot(), Dot(color=BLUE)
self.play(Create(e))
self.play(Create(f))
Additional media files
Gif output:
Note the repeated frame 15-16.
Comments and workarounds
This issue was found while working on a periodic background animation.
This seems related to self.update_to_time(t) (in Scene.play_internal, line 1259) not performing any update on the first frame t=0.
My current workaround is to modify line 1007 of scene.py:
Description of bug / unexpected behavior
Updaters are not updated correctly on the first / last frames of animations.
In the below code sample, the red dot is expected to continuously move rightwards every frame: however, after the first animation, a frame is duplicated.
(The updater seems to be run twice between these two frames, but both with
dt=0
.)Expected behavior
The updater should be run with
dt=1/framerate
, exactly once.How to reproduce the issue
Additional media files
Gif output: Note the repeated frame 15-16.
Comments and workarounds
This issue was found while working on a periodic background animation.
This seems related to
self.update_to_time(t)
(inScene.play_internal
, line 1259) not performing any update on the first framet=0
.My current workaround is to modify line 1007 of
scene.py
:to
System specifications
System Details
- OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): macOS Ventura 13.3.1 (a) - Python version (`python/py/python3 --version`): 3.10 - Manim version: v0.18.1