Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added :class:`~.Broadcast` animation. (#1719)

Laith Bahodi0cb577869363
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index adbef2ac3..4848a7d1b 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -134,6 +134,7 @@ Animations
~animation.movement
~animation.numbers
~animation.rotation
+ ~animation.specialized
~animation.transform
~animation.transform_matching_parts
~animation.update
@@ -151,6 +152,7 @@ Animations
manim.animation.movement
manim.animation.numbers
manim.animation.rotation
+ manim.animation.specialized
manim.animation.transform
manim.animation.transform_matching_parts
manim.animation.update
diff --git a/manim/__init__.py b/manim/__init__.py
index d9be9319f..8c12297db 100644
--- a/manim/__init__.py
+++ b/manim/__init__.py
@@ -42,6 +42,7 @@ from .animation.indication import *
from .animation.movement import *
from .animation.numbers import *
from .animation.rotation import *
+from .animation.specialized import *
from .animation.transform import *
from .animation.transform_matching_parts import *
from .animation.update import *
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
index 6c6555532..cfa016e96 100644
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -96,9 +96,9 @@ class Animation:
def __new__(
cls,
- mobject: Optional[Mobject] = None,
+ mobject=None,
*args,
- use_override: bool = True,
+ use_override=True,
**kwargs,
):
if isinstance(mobject, Mobject) and use_override:
diff --git a/manim/animation/specialized.py b/manim/animation/specialized.py
new file mode 100644
index 000000000..8d184e269
--- /dev/null
+++ b/manim/animation/specialized.py
@@ -0,0 +1,94 @@
+__all__ = ["Broadcast"]
+
+from typing import Any, Sequence
+
+from manim.animation.transform import Restore
+
+from ..constants import *
+from .composition import LaggedStart
+
+
+class Broadcast(LaggedStart):
+ """Broadcast a mobject starting from an ``initial_width``, up to the actual size of the mobject.
+
+ Parameters
+ ----------
+ mobject
+ The mobject to be broadcast.
+ focal_point
+ The center of the broadcast, by default ORIGIN.
+ n_mobs
+ The number of mobjects that emerge from the focal point, by default 5.
+ initial_opacity
+ The starting stroke opacity of the mobjects emitted from the broadcast, by default 1.
+ final_opacity
+ The final stroke opacity of the mobjects emitted from the broadcast, by default 0.
+ initial_width
+ The initial width of the mobjects, by default 0.0.
+ remover
+ Whether the mobjects should be removed from the scene after the animation, by default True.
+ lag_ratio
+ The time between each iteration of the mobject, by default 0.2.
+ run_time
+ The total duration of the animation, by default 3.
+ kwargs
+ Additional arguments to be passed to :class:`~.LaggedStart`.
+
+ Examples
+ ---------
+
+ .. manim:: BroadcastExample
+
+ class BroadcastExample(Scene):
+ def construct(self):
+ mob = Circle(radius=4, color=TEAL_A)
+ self.play(Broadcast(mob))
+ """
+
+ def __init__(
+ self,
+ mobject,
+ focal_point: Sequence[float] = ORIGIN,
+ n_mobs: int = 5,
+ initial_opacity: float = 1,
+ final_opacity: float = 0,
+ initial_width: float = 0.0,
+ remover: bool = True,
+ lag_ratio: float = 0.2,
+ run_time: float = 3,
+ **kwargs: Any
+ ):
+ self.focal_point = focal_point
+ self.n_mobs = n_mobs
+ self.initial_opacity = initial_opacity
+ self.final_opacity = final_opacity
+ self.initial_width = initial_width
+
+ anims = []
+
+ # Works by saving the mob that is passed into the animation, scaling it to 0 (or the initial_width) and then restoring the original mob.
+ if mobject.fill_opacity:
+ fill_o = True
+ else:
+ fill_o = False
+
+ for _ in range(self.n_mobs):
+ mob = mobject.copy()
+
+ if fill_o:
+ mob.set_opacity(self.final_opacity)
+ else:
+ mob.set_stroke(opacity=self.final_opacity)
+
+ mob.move_to(self.focal_point)
+ mob.save_state()
+ mob.set_width(self.initial_width)
+
+ if fill_o:
+ mob.set_opacity(self.initial_opacity)
+ else:
+ mob.set_stroke(opacity=self.initial_opacity)
+
+ anims.append(Restore(mob, remover=remover))
+
+ super().__init__(*anims, run_time=run_time, lag_ratio=lag_ratio, **kwargs)