A community-maintained Python framework for creating mathematical animations.
type growing.py half done indication.py
Syrus Dark415d5685acf8
diff --git a/manim/animation/growing.py b/manim/animation/growing.pyindex f1fb54b4a..421d1e3b6 100644--- a/manim/animation/growing.py+++ b/manim/animation/growing.py@@ -8,21 +8,30 @@ __all__ = ["SpinInFromNothing",]+import typing++import numpy as npfrom ..animation.transform import Transformfrom ..constants import PI+if typing.TYPE_CHECKING:+ from ..mobject.geometry import Arrow+ from ..mobject.mobject import Mobject+class GrowFromPoint(Transform):- def __init__(self, mobject, point, point_color=None, **kwargs):+ def __init__(+ self, mobject: "Mobject", point: np.ndarray, point_color: str = None, **kwargs+ ) -> None:self.point = pointself.point_color = point_colorsuper().__init__(mobject, **kwargs)- def create_target(self):+ def create_target(self) -> "Mobject":return self.mobject- def create_starting_mobject(self):+ def create_starting_mobject(self) -> "Mobject":start = super().create_starting_mobject()start.scale(0)start.move_to(self.point)@@ -32,23 +41,25 @@ class GrowFromPoint(Transform):class GrowFromCenter(GrowFromPoint):- def __init__(self, mobject, point_color=None, **kwargs):+ def __init__(self, mobject: "Mobject", point_color: str = None, **kwargs) -> None:point = mobject.get_center()super().__init__(mobject, point, point_color=point_color, **kwargs)class GrowFromEdge(GrowFromPoint):- def __init__(self, mobject, edge, **kwargs):+ def __init__(self, mobject: "Mobject", edge: np.ndarray, **kwargs) -> None:point = mobject.get_critical_point(edge)super().__init__(mobject, point, **kwargs)class GrowArrow(GrowFromPoint):- def __init__(self, arrow, **kwargs):+ def __init__(self, arrow: "Arrow", **kwargs) -> None:point = arrow.get_start()super().__init__(arrow, point, **kwargs)class SpinInFromNothing(GrowFromCenter):- def __init__(self, mobject, path_arc=PI, **kwargs):+ def __init__(+ self, mobject: "Mobject", path_arc: typing.Optional[float] = PI, **kwargs+ ) -> None:super().__init__(mobject, path_arc=path_arc, **kwargs)diff --git a/manim/animation/indication.py b/manim/animation/indication.pyindex 860973705..36a460791 100644--- a/manim/animation/indication.py+++ b/manim/animation/indication.py@@ -18,34 +18,40 @@ __all__ = []+import typing+import numpy as npfrom .. import config-from ..constants import *from ..animation.animation import Animation-from ..animation.movement import Homotopy-from ..animation.composition import AnimationGroup-from ..animation.composition import Succession-from ..animation.creation import ShowCreation-from ..animation.creation import ShowPartial+from ..animation.composition import AnimationGroup, Succession+from ..animation.creation import ShowCreation, ShowPartialfrom ..animation.fading import FadeOut+from ..animation.movement import Homotopyfrom ..animation.transform import Transform-from ..mobject.types.vectorized_mobject import VMobject-from ..mobject.geometry import Circle-from ..mobject.geometry import Dot+from ..constants import *+from ..mobject.geometry import Circle, Dot, Linefrom ..mobject.shape_matchers import SurroundingRectangle-from ..mobject.types.vectorized_mobject import VGroup-from ..mobject.geometry import Line+from ..mobject.types.vectorized_mobject import VGroup, VMobjectfrom ..utils.bezier import interpolate-from ..utils.rate_functions import there_and_back-from ..utils.rate_functions import wigglefrom ..utils.color import GREY, YELLOW+from ..utils.rate_functions import there_and_back, wiggle++if typing.TYPE_CHECKING:+ from ..mobject.geometry import Dot+ from ..mobject.mobject import Mobjectclass FocusOn(Transform):def __init__(- self, focus_point, opacity=0.2, color=GREY, run_time=2, remover=True, **kwargs- ):+ self,+ focus_point: np.ndarray,+ opacity: float = 0.2,+ color: str = GREY,+ run_time: float = 2,+ remover: bool = True,+ **kwargs+ ) -> None:self.focus_point = focus_pointself.color = colorself.opacity = opacity@@ -53,13 +59,13 @@ class FocusOn(Transform):# and create_starting_mobject handle the meatsuper().__init__(VMobject(), run_time=run_time, remover=remover, **kwargs)- def create_target(self):+ def create_target(self) -> "Dot":little_dot = Dot(radius=0)little_dot.set_fill(self.color, opacity=self.opacity)little_dot.add_updater(lambda d: d.move_to(self.focus_point))return little_dot- def create_starting_mobject(self):+ def create_starting_mobject(self) -> "Dot":return Dot(radius=config["frame_x_radius"] + config["frame_y_radius"],stroke_width=0,@@ -71,17 +77,19 @@ class FocusOn(Transform):class Indicate(Transform):def __init__(self,- mobject,- scale_factor=1.2,- color=YELLOW,- rate_func=there_and_back,+ mobject: "Mobject",+ scale_factor: float = 1.2,+ color: str = YELLOW,+ rate_func: typing.Callable[+ [float, typing.Optional[float]], np.ndarray+ ] = there_and_back,**kwargs- ):+ ) -> None:self.color = colorself.scale_factor = scale_factorsuper().__init__(mobject, rate_func=rate_func, **kwargs)- def create_target(self):+ def create_target(self) -> "Mobject":target = self.mobject.copy()target.scale_in_place(self.scale_factor)target.set_color(self.color)@@ -91,15 +99,15 @@ class Indicate(Transform):class Flash(AnimationGroup):def __init__(self,- point,- line_length=0.2,- num_lines=12,- flash_radius=0.3,- line_stroke_width=3,- color=YELLOW,- run_time=1,+ point: np.ndarray,+ line_length: typing.Optional[float] = 0.2,+ num_lines: typing.Optional[int] = 12,+ flash_radius: typing.Optional[float] = 0.3,+ line_stroke_width: typing.Optional[int] = 3,+ color: typing.Optional[str] = YELLOW,+ run_time: typing.Optional[int] = 1,**kwargs- ):+ ) -> None:self.point = pointself.color = colorself.line_length = line_length@@ -116,7 +124,7 @@ class Flash(AnimationGroup):**kwargs,)- def create_lines(self):+ def create_lines(self) -> VGroup:lines = VGroup()for angle in np.arange(0, TAU, TAU / self.num_lines):line = Line(ORIGIN, self.line_length * RIGHT)@@ -128,7 +136,7 @@ class Flash(AnimationGroup):lines.add_updater(lambda l: l.move_to(self.point))return lines- def create_line_anims(self):+ def create_line_anims(self) -> typing.Iterable["ShowCreationThenDestruction"]:return [ShowCreationThenDestruction(line) for line in self.lines]diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.pyindex 70ebe476c..7e69eb125 100644--- a/manim/utils/rate_functions.py+++ b/manim/utils/rate_functions.py@@ -106,7 +106,7 @@ def double_smooth(t: float) -> np.ndarray:return 0.5 * (1 + smooth(2 * t - 1))-def there_and_back(t: float, inflection: float = 10.0) -> np.ndarray:+def there_and_back(t: float, inflection: typing.Optional[float] = 10.0) -> np.ndarray:new_t = 2 * t if t < 0.5 else 2 * (1 - t)return smooth(new_t, inflection)