@@ -40,14 +40,16 @@ def construct(self):
40
40
]
41
41
42
42
from collections .abc import Iterable
43
- from typing import Callable
43
+ from typing import Any
44
44
45
45
import numpy as np
46
+ from typing_extensions import Self
46
47
47
48
from manim .mobject .geometry .arc import Circle , Dot
48
49
from manim .mobject .geometry .line import Line
49
50
from manim .mobject .geometry .polygram import Rectangle
50
51
from manim .mobject .geometry .shape_matchers import SurroundingRectangle
52
+ from manim .mobject .opengl .opengl_mobject import OpenGLMobject
51
53
from manim .scene .scene import Scene
52
54
53
55
from .. import config
@@ -61,9 +63,10 @@ def construct(self):
61
63
from ..constants import *
62
64
from ..mobject .mobject import Mobject
63
65
from ..mobject .types .vectorized_mobject import VGroup , VMobject
66
+ from ..typing import Point3D , Point3DLike , Vector3DLike
64
67
from ..utils .bezier import interpolate , inverse_interpolate
65
68
from ..utils .color import GREY , YELLOW , ParsableManimColor
66
- from ..utils .rate_functions import smooth , there_and_back , wiggle
69
+ from ..utils .rate_functions import RateFunction , smooth , there_and_back , wiggle
67
70
from ..utils .space_ops import normalize
68
71
69
72
@@ -95,12 +98,12 @@ def construct(self):
95
98
96
99
def __init__ (
97
100
self ,
98
- focus_point : np . ndarray | Mobject ,
101
+ focus_point : Point3DLike | Mobject ,
99
102
opacity : float = 0.2 ,
100
- color : str = GREY ,
103
+ color : ParsableManimColor = GREY ,
101
104
run_time : float = 2 ,
102
- ** kwargs ,
103
- ) -> None :
105
+ ** kwargs : Any ,
106
+ ):
104
107
self .focus_point = focus_point
105
108
self .color = color
106
109
self .opacity = opacity
@@ -151,15 +154,15 @@ def __init__(
151
154
self ,
152
155
mobject : Mobject ,
153
156
scale_factor : float = 1.2 ,
154
- color : str = YELLOW ,
155
- rate_func : Callable [[ float , float | None ], np . ndarray ] = there_and_back ,
156
- ** kwargs ,
157
- ) -> None :
157
+ color : ParsableManimColor = YELLOW ,
158
+ rate_func : RateFunction = there_and_back ,
159
+ ** kwargs : Any ,
160
+ ):
158
161
self .color = color
159
162
self .scale_factor = scale_factor
160
163
super ().__init__ (mobject , rate_func = rate_func , ** kwargs )
161
164
162
- def create_target (self ) -> Mobject :
165
+ def create_target (self ) -> Mobject | OpenGLMobject :
163
166
target = self .mobject .copy ()
164
167
target .scale (self .scale_factor )
165
168
target .set_color (self .color )
@@ -219,20 +222,20 @@ def construct(self):
219
222
220
223
def __init__ (
221
224
self ,
222
- point : np . ndarray | Mobject ,
225
+ point : Point3DLike | Mobject ,
223
226
line_length : float = 0.2 ,
224
227
num_lines : int = 12 ,
225
228
flash_radius : float = 0.1 ,
226
229
line_stroke_width : int = 3 ,
227
- color : str = YELLOW ,
230
+ color : ParsableManimColor = YELLOW ,
228
231
time_width : float = 1 ,
229
232
run_time : float = 1.0 ,
230
- ** kwargs ,
231
- ) -> None :
233
+ ** kwargs : Any ,
234
+ ):
232
235
if isinstance (point , Mobject ):
233
- self .point = point .get_center ()
236
+ self .point : Point3D = point .get_center ()
234
237
else :
235
- self .point = point
238
+ self .point = np . asarray ( point )
236
239
self .color = color
237
240
self .line_length = line_length
238
241
self .num_lines = num_lines
@@ -303,7 +306,9 @@ def construct(self):
303
306
304
307
"""
305
308
306
- def __init__ (self , mobject : VMobject , time_width : float = 0.1 , ** kwargs ) -> None :
309
+ def __init__ (
310
+ self , mobject : VMobject , time_width : float = 0.1 , ** kwargs : Any
311
+ ) -> None :
307
312
self .time_width = time_width
308
313
super ().__init__ (mobject , remover = True , introducer = True , ** kwargs )
309
314
@@ -322,7 +327,14 @@ def clean_up_from_scene(self, scene: Scene) -> None:
322
327
323
328
324
329
class ShowPassingFlashWithThinningStrokeWidth (AnimationGroup ):
325
- def __init__ (self , vmobject , n_segments = 10 , time_width = 0.1 , remover = True , ** kwargs ):
330
+ def __init__ (
331
+ self ,
332
+ vmobject : VMobject ,
333
+ n_segments : int = 10 ,
334
+ time_width : float = 0.1 ,
335
+ remover : bool = True ,
336
+ ** kwargs : Any ,
337
+ ):
326
338
self .n_segments = n_segments
327
339
self .time_width = time_width
328
340
self .remover = remover
@@ -389,19 +401,19 @@ def construct(self):
389
401
def __init__ (
390
402
self ,
391
403
mobject : Mobject ,
392
- direction : np . ndarray = UP ,
404
+ direction : Vector3DLike = UP ,
393
405
amplitude : float = 0.2 ,
394
- wave_func : Callable [[ float ], float ] = smooth ,
406
+ wave_func : RateFunction = smooth ,
395
407
time_width : float = 1 ,
396
408
ripples : int = 1 ,
397
409
run_time : float = 2 ,
398
- ** kwargs ,
399
- ) -> None :
410
+ ** kwargs : Any ,
411
+ ):
400
412
x_min = mobject .get_left ()[0 ]
401
413
x_max = mobject .get_right ()[0 ]
402
414
vect = amplitude * normalize (direction )
403
415
404
- def wave (t ) :
416
+ def wave (t : float ) -> float :
405
417
# Creates a wave with n ripples from a simple rate_func
406
418
# This wave is build up as follows:
407
419
# The time is split into 2*ripples phases. In every phase the amplitude
@@ -467,7 +479,8 @@ def homotopy(
467
479
relative_x = inverse_interpolate (x_min , x_max , x )
468
480
wave_phase = inverse_interpolate (lower , upper , relative_x )
469
481
nudge = wave (wave_phase ) * vect
470
- return np .array ([x , y , z ]) + nudge
482
+ return_value : tuple [float , float , float ] = np .array ([x , y , z ]) + nudge
483
+ return return_value
471
484
472
485
super ().__init__ (homotopy , mobject , run_time = run_time , ** kwargs )
473
486
@@ -511,24 +524,28 @@ def __init__(
511
524
scale_value : float = 1.1 ,
512
525
rotation_angle : float = 0.01 * TAU ,
513
526
n_wiggles : int = 6 ,
514
- scale_about_point : np . ndarray | None = None ,
515
- rotate_about_point : np . ndarray | None = None ,
527
+ scale_about_point : Point3DLike | None = None ,
528
+ rotate_about_point : Point3DLike | None = None ,
516
529
run_time : float = 2 ,
517
- ** kwargs ,
518
- ) -> None :
530
+ ** kwargs : Any ,
531
+ ):
519
532
self .scale_value = scale_value
520
533
self .rotation_angle = rotation_angle
521
534
self .n_wiggles = n_wiggles
522
535
self .scale_about_point = scale_about_point
536
+ if scale_about_point is not None :
537
+ self .scale_about_point = np .array (scale_about_point )
523
538
self .rotate_about_point = rotate_about_point
539
+ if rotate_about_point is not None :
540
+ self .rotate_about_point = np .array (rotate_about_point )
524
541
super ().__init__ (mobject , run_time = run_time , ** kwargs )
525
542
526
- def get_scale_about_point (self ) -> np . ndarray :
543
+ def get_scale_about_point (self ) -> Point3D :
527
544
if self .scale_about_point is None :
528
545
return self .mobject .get_center ()
529
546
return self .scale_about_point
530
547
531
- def get_rotate_about_point (self ) -> np . ndarray :
548
+ def get_rotate_about_point (self ) -> Point3D :
532
549
if self .rotate_about_point is None :
533
550
return self .mobject .get_center ()
534
551
return self .rotate_about_point
@@ -538,7 +555,7 @@ def interpolate_submobject(
538
555
submobject : Mobject ,
539
556
starting_submobject : Mobject ,
540
557
alpha : float ,
541
- ) -> None :
558
+ ) -> Self :
542
559
submobject .points [:, :] = starting_submobject .points
543
560
submobject .scale (
544
561
interpolate (1 , self .scale_value , there_and_back (alpha )),
@@ -548,6 +565,7 @@ def interpolate_submobject(
548
565
wiggle (alpha , self .n_wiggles ) * self .rotation_angle ,
549
566
about_point = self .get_rotate_about_point (),
550
567
)
568
+ return self
551
569
552
570
553
571
class Circumscribe (Succession ):
@@ -595,18 +613,18 @@ def construct(self):
595
613
def __init__ (
596
614
self ,
597
615
mobject : Mobject ,
598
- shape : type = Rectangle ,
599
- fade_in = False ,
600
- fade_out = False ,
601
- time_width = 0.3 ,
616
+ shape : type [ Rectangle ] | type [ Circle ] = Rectangle ,
617
+ fade_in : bool = False ,
618
+ fade_out : bool = False ,
619
+ time_width : float = 0.3 ,
602
620
buff : float = SMALL_BUFF ,
603
621
color : ParsableManimColor = YELLOW ,
604
- run_time = 1 ,
605
- stroke_width = DEFAULT_STROKE_WIDTH ,
606
- ** kwargs ,
622
+ run_time : float = 1 ,
623
+ stroke_width : float = DEFAULT_STROKE_WIDTH ,
624
+ ** kwargs : Any ,
607
625
):
608
626
if shape is Rectangle :
609
- frame = SurroundingRectangle (
627
+ frame : SurroundingRectangle | Circle = SurroundingRectangle (
610
628
mobject ,
611
629
color = color ,
612
630
buff = buff ,
@@ -685,7 +703,7 @@ def __init__(
685
703
time_off : float = 0.5 ,
686
704
blinks : int = 1 ,
687
705
hide_at_end : bool = False ,
688
- ** kwargs ,
706
+ ** kwargs : Any ,
689
707
):
690
708
animations = [
691
709
UpdateFromFunc (
0 commit comments