mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
[EXPERIMENTAL] Remove _on_finish parameter from Animation (#4595)
* Remove _on_finish parameter from Animation * Rewrite GenericGraph._add_vertices_animation() --------- Co-authored-by: Francisco Manríquez Novoa <francisco.manriquezn@usm.cl>
This commit is contained in:
parent
40c166153d
commit
6fb7fa4b2f
4 changed files with 29 additions and 23 deletions
|
|
@ -46,8 +46,21 @@ class Test(Scene):
|
|||
self.play(Unwrite(banner))
|
||||
|
||||
@group
|
||||
def never_run(self) -> None:
|
||||
self.play(Write(Text("This should never be run")))
|
||||
def graph(self):
|
||||
vertices = [1, 2, 3]
|
||||
edges = [(1, 2), (2, 3), (3, 1)]
|
||||
graph = Graph(vertices, edges, layout="circular")
|
||||
self.play(Create(graph))
|
||||
self.play(
|
||||
graph.animate.add_vertices(
|
||||
4,
|
||||
5,
|
||||
vertex_config={4: {"fill_color": RED}, 5: {"fill_color": RED}},
|
||||
positions={4: [2, 1, 0], 5: [2, -1, 0]},
|
||||
)
|
||||
)
|
||||
self.wait(1)
|
||||
self.play(Uncreate(graph))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -150,7 +150,6 @@ class Animation(AnimationProtocol):
|
|||
suspend_mobject_updating: bool = True,
|
||||
introducer: bool = False,
|
||||
*,
|
||||
_on_finish: Callable[[SceneBuffer], object] = lambda _: None,
|
||||
use_override: bool = True, # included here to avoid TypeError if passed from a subclass' constructor
|
||||
) -> None:
|
||||
self._typecheck_input(mobject)
|
||||
|
|
@ -162,7 +161,6 @@ class Animation(AnimationProtocol):
|
|||
self.introducer: bool = introducer
|
||||
self.suspend_mobject_updating: bool = suspend_mobject_updating
|
||||
self.lag_ratio: float = lag_ratio
|
||||
self._on_finish = _on_finish
|
||||
|
||||
self.buffer = SceneBuffer()
|
||||
self.apply_buffer = False # ask scene to apply buffer
|
||||
|
|
@ -250,8 +248,6 @@ class Animation(AnimationProtocol):
|
|||
if self.suspend_mobject_updating and self.mobject is not None:
|
||||
self.mobject.resume_updating()
|
||||
|
||||
# TODO: remove on_finish
|
||||
self._on_finish(self.buffer)
|
||||
if self.remover:
|
||||
self.buffer.remove(self.mobject)
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ class AnimationGroup(Animation):
|
|||
|
||||
if self.suspend_mobject_updating:
|
||||
self.group.resume_updating()
|
||||
self._on_finish(self.buffer)
|
||||
|
||||
def update_mobjects(self, dt: float) -> None:
|
||||
for anim in self.anims_with_timings["anim"][
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import numpy as np
|
|||
if TYPE_CHECKING:
|
||||
from typing import TypeAlias
|
||||
|
||||
from manim.scene.scene import Scene
|
||||
from manim.typing import Point3D, Point3DLike
|
||||
|
||||
NxGraph: TypeAlias = nx.classes.graph.Graph | nx.classes.digraph.DiGraph
|
||||
|
|
@ -858,7 +857,7 @@ class GenericGraph(VMobject):
|
|||
vertex_type: type[Mobject] = Dot,
|
||||
vertex_config: dict | None = None,
|
||||
vertex_mobjects: dict | None = None,
|
||||
):
|
||||
) -> list[Mobject]:
|
||||
"""Add a list of vertices to the graph.
|
||||
|
||||
Parameters
|
||||
|
|
@ -901,23 +900,22 @@ class GenericGraph(VMobject):
|
|||
]
|
||||
|
||||
@override_animate(add_vertices)
|
||||
def _add_vertices_animation(self, *args, anim_args=None, **kwargs):
|
||||
if anim_args is None:
|
||||
anim_args = {}
|
||||
def _add_vertices_animation(
|
||||
self,
|
||||
*vertices: Hashable,
|
||||
anim_args: dict[str, Any] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> AnimationGroup:
|
||||
vertex_mobjects = self.add_vertices(*vertices, **kwargs)
|
||||
|
||||
animation = anim_args.pop("animation", Create)
|
||||
|
||||
vertex_mobjects = self._create_vertices(*args, **kwargs)
|
||||
|
||||
def on_finish(scene: Scene):
|
||||
for v in vertex_mobjects:
|
||||
scene.remove(v[-1])
|
||||
self._add_created_vertex(*v)
|
||||
base_anim_args = {"animation": Create, "introducer": False}
|
||||
if anim_args is not None:
|
||||
base_anim_args.update(anim_args)
|
||||
animation = base_anim_args.pop("animation")
|
||||
|
||||
return AnimationGroup(
|
||||
*(animation(v[-1], **anim_args) for v in vertex_mobjects),
|
||||
group=self,
|
||||
_on_finish=on_finish,
|
||||
animation(vertex_mobject, **base_anim_args)
|
||||
for vertex_mobject in vertex_mobjects
|
||||
)
|
||||
|
||||
def _remove_vertex(self, vertex):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue