Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed :class:`~.DrawBorderThenFill` to support OpenGL and improved type hints for some functions (#1156)

Mohammad Al-Fetyani219361a1338f
diff --git a/manim/animation/creation.py b/manim/animation/creation.py
index c265c2989..e21f7005a 100644
--- a/manim/animation/creation.py
+++ b/manim/animation/creation.py
@@ -105,10 +105,8 @@ class ShowPartial(Animation):
"""
- def __init__(self, mobject: VMobject, **kwargs):
- if not isinstance(mobject, VMobject) and not isinstance(
- mobject, OpenGLVMobject
- ):
+ def __init__(self, mobject: typing.Union[VMobject, OpenGLVMobject], **kwargs):
+ if not isinstance(mobject, (VMobject, OpenGLVMobject)):
raise TypeError("This Animation only works on vectorized mobjects")
super().__init__(mobject, **kwargs)
@@ -150,7 +148,12 @@ class Create(ShowPartial):
"""
- def __init__(self, mobject: VMobject, lag_ratio: float = 1.0, **kwargs) -> None:
+ def __init__(
+ self,
+ mobject: typing.Union[VMobject, OpenGLVMobject],
+ lag_ratio: float = 1.0,
+ **kwargs,
+ ) -> None:
super().__init__(mobject, lag_ratio=lag_ratio, **kwargs)
def _get_bounds(self, alpha: float) -> typing.Tuple[int, float]:
@@ -189,7 +192,7 @@ class Uncreate(Create):
def __init__(
self,
- mobject: VMobject,
+ mobject: typing.Union[VMobject, OpenGLVMobject],
rate_func: typing.Callable[[float, float], np.ndarray] = lambda t: smooth(
1 - t
),
@@ -213,7 +216,7 @@ class DrawBorderThenFill(Animation):
def __init__(
self,
- vmobject: VMobject,
+ vmobject: typing.Union[VMobject, OpenGLVMobject],
run_time: float = 2,
rate_func: typing.Callable[[float], np.ndarray] = double_smooth,
stroke_width: float = 2,
@@ -230,9 +233,11 @@ class DrawBorderThenFill(Animation):
self.fill_animation_config = fill_animation_config
self.outline = None
- def _typecheck_input(self, vmobject: VMobject) -> None:
- if not isinstance(vmobject, VMobject):
- raise TypeError("DrawBorderThenFill only works for VMobjects")
+ def _typecheck_input(
+ self, vmobject: typing.Union[VMobject, OpenGLVMobject]
+ ) -> None:
+ if not isinstance(vmobject, (VMobject, OpenGLVMobject)):
+ raise TypeError("DrawBorderThenFill only works for vectorized Mobjects")
def begin(self) -> None:
self.outline = self.get_outline()
@@ -245,7 +250,9 @@ class DrawBorderThenFill(Animation):
sm.set_stroke(color=self.get_stroke_color(sm), width=self.stroke_width)
return outline
- def get_stroke_color(self, vmobject: VMobject) -> Color:
+ def get_stroke_color(
+ self, vmobject: typing.Union[VMobject, OpenGLVMobject]
+ ) -> Color:
if self.stroke_color:
return self.stroke_color
elif vmobject.get_stroke_width() > 0:
@@ -280,7 +287,7 @@ class Write(DrawBorderThenFill):
def __init__(
self,
- vmobject: VMobject,
+ vmobject: typing.Union[VMobject, OpenGLVMobject],
run_time: float = None,
lag_ratio: float = None,
rate_func: typing.Callable[[float], np.ndarray] = linear,
@@ -297,7 +304,9 @@ class Write(DrawBorderThenFill):
**kwargs,
)
- def _set_default_config_from_length(self, vmobject: VMobject) -> None:
+ def _set_default_config_from_length(
+ self, vmobject: typing.Union[VMobject, OpenGLVMobject]
+ ) -> None:
length = len(vmobject.family_members_with_points())
if self.run_time is None:
if length < 15:
diff --git a/manim/animation/fading.py b/manim/animation/fading.py
index de2f49a9d..40ab5a7b7 100644
--- a/manim/animation/fading.py
+++ b/manim/animation/fading.py
@@ -74,6 +74,7 @@ from ..animation.animation import Animation
from ..animation.transform import Transform
from ..constants import DOWN
from ..mobject.types.vectorized_mobject import VMobject
+from ..mobject.types.opengl_vectorized_mobject import OpenGLVMobject
from ..utils.bezier import interpolate
from ..utils.rate_functions import there_and_back
@@ -89,7 +90,7 @@ class FadeOut(Transform):
def __init__(
self,
- vmobject: VMobject,
+ vmobject: typing.Union[VMobject, OpenGLVMobject],
remover: bool = True,
lag_ratio: float = DEFAULT_FADE_LAG_RATIO,
**kwargs
@@ -106,7 +107,10 @@ class FadeOut(Transform):
class FadeIn(Transform):
def __init__(
- self, vmobject: VMobject, lag_ratio: float = DEFAULT_FADE_LAG_RATIO, **kwargs
+ self,
+ vmobject: typing.Union[VMobject, OpenGLVMobject],
+ lag_ratio: float = DEFAULT_FADE_LAG_RATIO,
+ **kwargs
) -> None:
super().__init__(vmobject, lag_ratio=lag_ratio, **kwargs)
@@ -116,7 +120,7 @@ class FadeIn(Transform):
def create_starting_mobject(self) -> "Mobject":
start = super().create_starting_mobject()
start.fade(1)
- if isinstance(start, VMobject):
+ if isinstance(start, (VMobject, OpenGLVMobject)):
start.set_stroke(opacity=0)
start.set_fill(opacity=0)
return start