Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added documentation for scene updater functions (#2663)

Benjamin Hackl842a57eac918
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 2fc4add87..397fab6a8 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -345,7 +345,22 @@ class Scene:
for mesh in obj.get_family():
mesh.update(dt)
- def update_self(self, dt):
+ def update_self(self, dt: float):
+ """Run all scene updater functions.
+
+ Among all types of update functions (mobject updaters, mesh updaters,
+ scene updaters), scene update functions are called last.
+
+ Parameters
+ ----------
+ dt
+ Scene time since last update.
+
+ See Also
+ --------
+ :meth:`.Scene.add_updater`
+ :meth:`.Scene.remove_updater`
+ """
for func in self.updaters:
func(dt)
@@ -503,10 +518,50 @@ class Scene:
self.restructure_mobjects(mobjects, list_name, False)
return self
- def add_updater(self, func):
+ def add_updater(self, func: Callable[[float], None]) -> None:
+ """Add an update function to the scene.
+
+ The scene updater functions are run every frame,
+ and they are the last type of updaters to run.
+
+ .. WARNING::
+
+ When using the Cairo renderer, scene updaters that
+ modify mobjects are not detected in the same way
+ that mobject updaters are. To be more concrete,
+ a mobject only modified via a scene updater will
+ not necessarily be added to the list of *moving
+ mobjects* and thus might not be updated every frame.
+
+ TL;DR: Use mobject updaters to update mobjects.
+
+ Parameters
+ ----------
+ func
+ The updater function. It takes a float, which is the
+ time difference since the last update (usually equal
+ to the frame rate).
+
+ See also
+ --------
+ :meth:`.Scene.remove_updater`
+ :meth:`.Scene.update_self`
+ """
self.updaters.append(func)
- def remove_updater(self, func):
+ def remove_updater(self, func: Callable[[float], None]) -> None:
+ """Remove an update function from the scene.
+
+ Parameters
+ ----------
+ func
+ The updater function to be removed.
+
+ See also
+ --------
+ :meth:`.Scene.add_updater`
+ :meth:`.Scene.update_self`
+ """
self.updaters = [f for f in self.updaters if f is not func]
def restructure_mobjects(