2
2
3
3
from __future__ import annotations
4
4
5
- import types
6
5
from collections .abc import Iterable , Sequence
7
- from typing import TYPE_CHECKING , Callable
6
+ from typing import TYPE_CHECKING , Any , Callable
8
7
9
8
import numpy as np
10
9
11
10
from manim ._config import config
12
11
from manim .animation .animation import Animation , prepare_animation
13
12
from manim .constants import RendererType
14
13
from manim .mobject .mobject import Group , Mobject
15
- from manim .mobject .opengl .opengl_mobject import OpenGLGroup
14
+ from manim .mobject .opengl .opengl_mobject import OpenGLGroup , OpenGLMobject
16
15
from manim .scene .scene import Scene
17
16
from manim .utils .iterables import remove_list_redundancies
18
17
from manim .utils .parameter_parsing import flatten_iterable_parameters
@@ -54,31 +53,34 @@ class AnimationGroup(Animation):
54
53
55
54
def __init__ (
56
55
self ,
57
- * animations : Animation | Iterable [Animation ] | types . GeneratorType [ Animation ] ,
58
- group : Group | VGroup | OpenGLGroup | OpenGLVGroup = None ,
56
+ * animations : Animation | Iterable [Animation ],
57
+ group : Group | VGroup | OpenGLGroup | OpenGLVGroup | None = None ,
59
58
run_time : float | None = None ,
60
59
rate_func : Callable [[float ], float ] = linear ,
61
60
lag_ratio : float = 0 ,
62
- ** kwargs ,
63
- ) -> None :
61
+ ** kwargs : Any ,
62
+ ):
64
63
arg_anim = flatten_iterable_parameters (animations )
65
64
self .animations = [prepare_animation (anim ) for anim in arg_anim ]
66
65
self .rate_func = rate_func
67
- self .group = group
68
- if self .group is None :
66
+ if group is None :
69
67
mobjects = remove_list_redundancies (
70
68
[anim .mobject for anim in self .animations if not anim .is_introducer ()],
71
69
)
72
70
if config ["renderer" ] == RendererType .OPENGL :
73
- self .group = OpenGLGroup (* mobjects )
71
+ self .group : Group | VGroup | OpenGLGroup | OpenGLVGroup = OpenGLGroup (
72
+ * mobjects
73
+ )
74
74
else :
75
75
self .group = Group (* mobjects )
76
+ else :
77
+ self .group = group
76
78
super ().__init__ (
77
79
self .group , rate_func = self .rate_func , lag_ratio = lag_ratio , ** kwargs
78
80
)
79
81
self .run_time : float = self .init_run_time (run_time )
80
82
81
- def get_all_mobjects (self ) -> Sequence [Mobject ]:
83
+ def get_all_mobjects (self ) -> Sequence [Mobject | OpenGLMobject ]:
82
84
return list (self .group )
83
85
84
86
def begin (self ) -> None :
@@ -93,7 +95,7 @@ def begin(self) -> None:
93
95
for anim in self .animations :
94
96
anim .begin ()
95
97
96
- def _setup_scene (self , scene ) -> None :
98
+ def _setup_scene (self , scene : Scene ) -> None :
97
99
for anim in self .animations :
98
100
anim ._setup_scene (scene )
99
101
@@ -118,7 +120,7 @@ def update_mobjects(self, dt: float) -> None:
118
120
]:
119
121
anim .update_mobjects (dt )
120
122
121
- def init_run_time (self , run_time ) -> float :
123
+ def init_run_time (self , run_time : float | None ) -> float :
122
124
"""Calculates the run time of the animation, if different from ``run_time``.
123
125
124
126
Parameters
@@ -146,9 +148,9 @@ def build_animations_with_timings(self) -> None:
146
148
run_times = np .array ([anim .run_time for anim in self .animations ])
147
149
num_animations = run_times .shape [0 ]
148
150
dtype = [("anim" , "O" ), ("start" , "f8" ), ("end" , "f8" )]
149
- self .anims_with_timings = np .zeros (num_animations , dtype = dtype )
150
- self .anims_begun = np .zeros (num_animations , dtype = bool )
151
- self .anims_finished = np .zeros (num_animations , dtype = bool )
151
+ self .anims_with_timings : np . ndarray = np .zeros (num_animations , dtype = dtype )
152
+ self .anims_begun : np . ndarray = np .zeros (num_animations , dtype = bool )
153
+ self .anims_finished : np . ndarray = np .zeros (num_animations , dtype = bool )
152
154
if num_animations == 0 :
153
155
return
154
156
@@ -228,7 +230,7 @@ def construct(self):
228
230
))
229
231
"""
230
232
231
- def __init__ (self , * animations : Animation , lag_ratio : float = 1 , ** kwargs ) -> None :
233
+ def __init__ (self , * animations : Animation , lag_ratio : float = 1 , ** kwargs : Any ) :
232
234
super ().__init__ (* animations , lag_ratio = lag_ratio , ** kwargs )
233
235
234
236
def begin (self ) -> None :
@@ -247,7 +249,7 @@ def update_mobjects(self, dt: float) -> None:
247
249
if self .active_animation :
248
250
self .active_animation .update_mobjects (dt )
249
251
250
- def _setup_scene (self , scene ) -> None :
252
+ def _setup_scene (self , scene : Scene | None ) -> None :
251
253
if scene is None :
252
254
return
253
255
if self .is_introducer ():
@@ -339,7 +341,7 @@ def __init__(
339
341
self ,
340
342
* animations : Animation ,
341
343
lag_ratio : float = DEFAULT_LAGGED_START_LAG_RATIO ,
342
- ** kwargs ,
344
+ ** kwargs : Any ,
343
345
):
344
346
super ().__init__ (* animations , lag_ratio = lag_ratio , ** kwargs )
345
347
@@ -384,20 +386,22 @@ def construct(self):
384
386
385
387
def __init__ (
386
388
self ,
387
- AnimationClass : Callable [..., Animation ],
389
+ animation_class : type [ Animation ],
388
390
mobject : Mobject ,
389
- arg_creator : Callable [[Mobject ], str ] = None ,
391
+ arg_creator : Callable [[Mobject ], Iterable [ Any ]] | None = None ,
390
392
run_time : float = 2 ,
391
- ** kwargs ,
392
- ) -> None :
393
- args_list = []
394
- for submob in mobject :
395
- if arg_creator :
396
- args_list .append (arg_creator (submob ))
397
- else :
398
- args_list .append ((submob ,))
393
+ ** kwargs : Any ,
394
+ ):
395
+ if arg_creator is None :
396
+
397
+ def identity (mob : Mobject ) -> Mobject :
398
+ return mob
399
+
400
+ arg_creator = identity
401
+
402
+ args_list = [arg_creator (submob ) for submob in mobject ]
399
403
anim_kwargs = dict (kwargs )
400
404
if "lag_ratio" in anim_kwargs :
401
405
anim_kwargs .pop ("lag_ratio" )
402
- animations = [AnimationClass (* args , ** anim_kwargs ) for args in args_list ]
406
+ animations = [animation_class (* args , ** anim_kwargs ) for args in args_list ]
403
407
super ().__init__ (* animations , run_time = run_time , ** kwargs )
0 commit comments