Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

completed typing rate_function.py typed indication.py

Syrus Dark77fbfef0df7b
diff --git a/manim/animation/indication.py b/manim/animation/indication.py
index 36a460791..ace4ca2d5 100644
--- a/manim/animation/indication.py
+++ b/manim/animation/indication.py
@@ -143,22 +143,24 @@ class Flash(AnimationGroup):
class CircleIndicate(Indicate):
def __init__(
self,
- mobject,
- circle_config={"color": YELLOW},
- rate_func=there_and_back,
- remover=True,
+ mobject: "Mobject",
+ circle_config: typing.Dict[str, typing.Any] = {"color": YELLOW},
+ rate_func: typing.Callable[
+ [float, typing.Optional[float]], np.ndarray
+ ] = there_and_back,
+ remover: bool = True,
**kwargs
- ):
+ ) -> None:
self.circle_config = circle_config
circle = self.get_circle(mobject)
super().__init__(circle, rate_func=rate_func, remover=remover, **kwargs)
- def get_circle(self, mobject):
+ def get_circle(self, mobject: "Mobject") -> Circle:
circle = Circle(**self.circle_config)
circle.add_updater(lambda c: c.surround(mobject))
return circle
- def interpolate_mobject(self, alpha):
+ def interpolate_mobject(self, alpha: float) -> None:
super().interpolate_mobject(alpha)
self.mobject.set_stroke(opacity=alpha)
@@ -181,11 +183,17 @@ class ShowPassingFlash(ShowPartial):
"""
- def __init__(self, mobject, time_width=0.1, remover=True, **kwargs):
+ def __init__(
+ self,
+ mobject: "Mobject",
+ time_width: float = 0.1,
+ remover: bool = True,
+ **kwargs
+ ) -> None:
self.time_width = time_width
super().__init__(mobject, remover=remover, **kwargs)
- def _get_bounds(self, alpha):
+ def _get_bounds(self, alpha: float) -> typing.Tuple[float]:
tw = self.time_width
upper = interpolate(0, 1 + tw, alpha)
lower = upper - tw
@@ -193,19 +201,21 @@ class ShowPassingFlash(ShowPartial):
lower = max(lower, 0)
return (lower, upper)
- def finish(self):
+ def finish(self) -> None:
super().finish()
for submob, start in self.get_all_families_zipped():
submob.pointwise_become_partial(start, 0, 1)
class ShowCreationThenDestruction(ShowPassingFlash):
- def __init__(self, mobject, time_width=2.0, run_time=1, **kwargs):
+ def __init__(
+ self, mobject: "Mobject", time_width: float = 2.0, run_time: float = 1, **kwargs
+ ) -> None:
super().__init__(mobject, time_width=time_width, run_time=run_time, **kwargs)
class ShowCreationThenFadeOut(Succession):
- def __init__(self, mobject, remover=True, **kwargs):
+ def __init__(self, mobject: "Mobject", remover: bool = True, **kwargs) -> None:
super().__init__(
ShowCreation(mobject), FadeOut(mobject), remover=remover, **kwargs
)
@@ -214,11 +224,11 @@ class ShowCreationThenFadeOut(Succession):
class AnimationOnSurroundingRectangle(AnimationGroup):
def __init__(
self,
- mobject,
- rect_animation=Animation,
- surrounding_rectangle_config={},
+ mobject: "Mobject",
+ rect_animation: Animation = Animation,
+ surrounding_rectangle_config: typing.Dict[str, typing.Any] = {},
**kwargs
- ):
+ ) -> None:
# Callable which takes in a rectangle, and spits out some animation. Could be
# some animation class, could be something more
self.rect_animation = rect_animation
@@ -232,36 +242,57 @@ class AnimationOnSurroundingRectangle(AnimationGroup):
self.rect_animation(rect, **kwargs),
)
- def get_rect(self):
+ def get_rect(self) -> SurroundingRectangle:
return SurroundingRectangle(
self.mobject_to_surround, **self.surrounding_rectangle_config
)
class ShowPassingFlashAround(AnimationOnSurroundingRectangle):
- def __init__(self, mobject, rect_animation=ShowPassingFlash, **kwargs):
+ def __init__(
+ self, mobject: "Mobject", rect_animation: Animation = ShowPassingFlash, **kwargs
+ ) -> None:
super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ShowCreationThenDestructionAround(AnimationOnSurroundingRectangle):
- def __init__(self, mobject, rect_animation=ShowCreationThenDestruction, **kwargs):
+ def __init__(
+ self,
+ mobject: "Mobject",
+ rect_animation: Animation = ShowCreationThenDestruction,
+ **kwargs
+ ) -> None:
super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ShowCreationThenFadeAround(AnimationOnSurroundingRectangle):
- def __init__(self, mobject, rect_animation=ShowCreationThenFadeOut, **kwargs):
+ def __init__(
+ self,
+ mobject: "Mobject",
+ rect_animation: Animation = ShowCreationThenFadeOut,
+ **kwargs
+ ) -> None:
super().__init__(mobject, rect_animation=rect_animation, **kwargs)
class ApplyWave(Homotopy):
- def __init__(self, mobject, direction=UP, amplitude=0.2, run_time=1, **kwargs):
+ def __init__(
+ self,
+ mobject: "Mobject",
+ direction: np.ndarray = UP,
+ amplitude: float = 0.2,
+ run_time: float = 1,
+ **kwargs
+ ) -> None:
self.direction = direction
self.amplitude = amplitude
left_x = mobject.get_left()[0]
right_x = mobject.get_right()[0]
vect = self.amplitude * self.direction
- def homotopy(x, y, z, t):
+ def homotopy(
+ x: float, y: float, z: float, t: float
+ ) -> typing.Tuple[float, float, float]:
alpha = (x - left_x) / (right_x - left_x)
power = np.exp(2.0 * (alpha - 0.5))
nudge = there_and_back(t ** power)
@@ -273,15 +304,15 @@ class ApplyWave(Homotopy):
class WiggleOutThenIn(Animation):
def __init__(
self,
- mobject,
- scale_value=1.1,
- rotation_angle=0.01 * TAU,
- n_wiggles=6,
- scale_about_point=None,
- rotate_about_point=None,
- run_time=2,
+ mobject: "Mobject",
+ scale_value: float = 1.1,
+ rotation_angle: float = 0.01 * TAU,
+ n_wiggles: int = 6,
+ scale_about_point: typing.Optional[np.ndarray] = None,
+ rotate_about_point: typing.Optional[np.ndarray] = None,
+ run_time: float = 2,
**kwargs
- ):
+ ) -> None:
self.scale_value = scale_value
self.rotation_angle = rotation_angle
self.n_wiggles = n_wiggles
@@ -289,15 +320,17 @@ class WiggleOutThenIn(Animation):
self.rotate_about_point = rotate_about_point
super().__init__(mobject, run_time=run_time, **kwargs)
- def get_scale_about_point(self):
+ def get_scale_about_point(self) -> np.ndarray:
if self.scale_about_point is None:
return self.mobject.get_center()
- def get_rotate_about_point(self):
+ def get_rotate_about_point(self) -> np.ndarray:
if self.rotate_about_point is None:
return self.mobject.get_center()
- def interpolate_submobject(self, submobject, starting_sumobject, alpha):
+ def interpolate_submobject(
+ self, submobject: "Mobject", starting_sumobject: "Mobject", alpha: float
+ ) -> None:
submobject.points[:, :] = starting_sumobject.points
submobject.scale(
interpolate(1, self.scale_value, there_and_back(alpha)),
@@ -310,8 +343,8 @@ class WiggleOutThenIn(Animation):
class TurnInsideOut(Transform):
- def __init__(self, mobject, path_arc=TAU / 4, **kwargs):
+ def __init__(self, mobject: "Mobject", path_arc: float = TAU / 4, **kwargs) -> None:
super().__init__(mobject, path_arc=path_arc, **kwargs)
- def create_target(self):
+ def create_target(self) -> "Mobject":
return self.mobject.copy().reverse_points()
diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.py
index 7e69eb125..f16304f77 100644
--- a/manim/utils/rate_functions.py
+++ b/manim/utils/rate_functions.py
@@ -168,81 +168,81 @@ def lingering(t: float) -> typing.Callable: # not sure of return type
return squish_rate_func(lambda t: t, 0, 0.8)(t)
-def exponential_decay(t, half_life=0.1):
+def exponential_decay(t:np.ndarray, half_life:float=0.1) -> np.ndarray:
# The half-life should be rather small to minimize
# the cut-off error at the end
return 1 - np.exp(-t / half_life)
-def ease_in_sine(t):
+def ease_in_sine(t:np.ndarray) -> float:
return 1 - np.cos((t * np.pi) / 2)
-def ease_out_sine(t):
+def ease_out_sine(t:np.ndarray) -> float:
return np.sin((t * np.pi) / 2)
-def ease_in_out_sine(t):
+def ease_in_out_sine(t:np.ndarray) -> float:
return -(np.cos(np.pi * t) - 1) / 2
-def ease_in_quad(t):
+def ease_in_quad(t:float) -> float:
return t * t
-def ease_out_quad(t):
+def ease_out_quad(t:float) -> float:
return 1 - (1 - t) * (1 - t)
-def ease_in_out_quad(t):
+def ease_in_out_quad(t:float) -> float:
return 2 * t * t if t < 0.5 else 1 - pow(-2 * t + 2, 2) / 2
-def ease_in_cubic(t):
+def ease_in_cubic(t:float) -> float:
return t * t * t
-def ease_out_cubic(t):
+def ease_out_cubic(t:float) -> float:
return 1 - pow(1 - t, 3)
-def ease_in_out_cubic(t):
+def ease_in_out_cubic(t:float) -> float:
return 4 * t * t * t if t < 0.5 else 1 - pow(-2 * t + 2, 3) / 2
-def ease_in_quart(t):
+def ease_in_quart(t:float) -> float:
return t * t * t * t
-def ease_out_quart(t):
+def ease_out_quart(t:float ) -> float:
return 1 - pow(1 - t, 4)
-def ease_in_out_quart(t):
+def ease_in_out_quart(t:float) -> float:
return 8 * t * t * t * t if t < 0.5 else 1 - pow(-2 * t + 2, 4) / 2
-def ease_in_quint(t):
+def ease_in_quint(t:float) -> float:
return t * t * t * t * t
-def ease_out_quint(t):
+def ease_out_quint(t:float) -> float:
return 1 - pow(1 - t, 5)
-def ease_in_out_quint(t):
+def ease_in_out_quint(t:float) -> float:
return 16 * t * t * t * t * t if t < 0.5 else 1 - pow(-2 * t + 2, 5) / 2
-def ease_in_expo(t):
+def ease_in_expo(t:float) -> float:
return 0 if t == 0 else pow(2, 10 * t - 10)
-def ease_out_expo(t):
+def ease_out_expo(t:float) -> float:
return 1 if t == 1 else 1 - pow(2, -10 * t)
-def ease_in_out_expo(t):
+def ease_in_out_expo(t:float) -> float:
if t == 0:
return 0
elif t == 1:
@@ -253,15 +253,15 @@ def ease_in_out_expo(t):
return 2 - pow(2, -20 * t + 10) / 2
-def ease_in_circ(t):
+def ease_in_circ(t:float) -> float:
return 1 - sqrt(1 - pow(t, 2))
-def ease_out_circ(t):
+def ease_out_circ(t:float) -> float:
return sqrt(1 - pow(t - 1, 2))
-def ease_in_out_circ(t):
+def ease_in_out_circ(t:float)-> float:
return (
(1 - sqrt(1 - pow(2 * t, 2))) / 2
if t < 0.5
@@ -269,19 +269,19 @@ def ease_in_out_circ(t):
)
-def ease_in_back(t):
+def ease_in_back(t:float) ->float:
c1 = 1.70158
c3 = c1 + 1
return c3 * t * t * t - c1 * t * t
-def ease_out_back(t):
+def ease_out_back(t:float) -> float:
c1 = 1.70158
c3 = c1 + 1
return 1 + c3 * pow(t - 1, 3) + c1 * pow(t - 1, 2)
-def ease_in_out_back(t):
+def ease_in_out_back(t:float) -> float:
c1 = 1.70158
c2 = c1 * 1.525
return (
@@ -291,7 +291,7 @@ def ease_in_out_back(t):
)
-def ease_in_elastic(t):
+def ease_in_elastic(t:float) -> float:
c4 = (2 * np.pi) / 3
if t == 0:
return 0
@@ -301,7 +301,7 @@ def ease_in_elastic(t):
return -pow(2, 10 * t - 10) * np.sin((t * 10 - 10.75) * c4)
-def ease_out_elastic(t):
+def ease_out_elastic(t:float) -> float:
c4 = (2 * np.pi) / 3
if t == 0:
return 0
@@ -311,7 +311,7 @@ def ease_out_elastic(t):
return pow(2, -10 * t) * np.sin((t * 10 - 0.75) * c4) + 1
-def ease_in_out_elastic(t):
+def ease_in_out_elastic(t:float) -> float:
c5 = (2 * np.pi) / 4.5
if t == 0:
return 0
@@ -323,11 +323,11 @@ def ease_in_out_elastic(t):
return (pow(2, -20 * t + 10) * np.sin((20 * t - 11.125) * c5)) / 2 + 1
-def ease_in_bounce(t):
+def ease_in_bounce(t:float) -> float:
return 1 - ease_out_bounce(1 - t)
-def ease_out_bounce(t):
+def ease_out_bounce(t:float) -> float:
n1 = 7.5625
d1 = 2.75
@@ -341,7 +341,7 @@ def ease_out_bounce(t):
return n1 * (t - 2.625 / d1) * t + 0.984375
-def ease_in_out_bounce(t):
+def ease_in_out_bounce(t:float) -> float:
c1 = 1.70158
c2 = c1 * 1.525
return (