mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
fix(lib): use optional instead of mutable defaults (#291)
* fix(lib): use optional instead of mutable defaults * fix: add missing check for none
This commit is contained in:
@ -11,7 +11,7 @@ that directly calls ``self.play(Animation(...))``, see
|
|||||||
|
|
||||||
__all__ = ["Wipe", "Zoom"]
|
__all__ = ["Wipe", "Zoom"]
|
||||||
|
|
||||||
from typing import Any, Mapping, Sequence
|
from typing import Any, Mapping, Optional, Sequence
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@ -62,20 +62,28 @@ class Wipe(AnimationGroup): # type: ignore[misc]
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
current: Sequence[Mobject] = [],
|
current: Optional[Sequence[Mobject]] = None,
|
||||||
future: Sequence[Mobject] = [],
|
future: Optional[Sequence[Mobject]] = None,
|
||||||
shift: np.ndarray = LEFT,
|
shift: np.ndarray = LEFT,
|
||||||
fade_in_kwargs: Mapping[str, Any] = {},
|
fade_in_kwargs: Optional[Mapping[str, Any]] = None,
|
||||||
fade_out_kwargs: Mapping[str, Any] = {},
|
fade_out_kwargs: Optional[Mapping[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
):
|
):
|
||||||
animations = []
|
animations = []
|
||||||
|
|
||||||
for mobject in future:
|
if future:
|
||||||
animations.append(FadeIn(mobject, shift=shift, **fade_in_kwargs))
|
if fade_in_kwargs is None:
|
||||||
|
fade_in_kwargs = {}
|
||||||
|
|
||||||
for mobject in current:
|
for mobject in future:
|
||||||
animations.append(FadeOut(mobject, shift=shift, **fade_out_kwargs))
|
animations.append(FadeIn(mobject, shift=shift, **fade_in_kwargs))
|
||||||
|
|
||||||
|
if current:
|
||||||
|
if fade_out_kwargs is None:
|
||||||
|
fade_out_kwargs = {}
|
||||||
|
|
||||||
|
for mobject in current:
|
||||||
|
animations.append(FadeOut(mobject, shift=shift, **fade_out_kwargs))
|
||||||
|
|
||||||
super().__init__(*animations, **kwargs)
|
super().__init__(*animations, **kwargs)
|
||||||
|
|
||||||
@ -118,12 +126,12 @@ class Zoom(AnimationGroup): # type: ignore[misc]
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
current: Sequence[Mobject] = [],
|
current: Optional[Sequence[Mobject]] = None,
|
||||||
future: Sequence[Mobject] = [],
|
future: Optional[Sequence[Mobject]] = None,
|
||||||
scale: float = 4.0,
|
scale: float = 4.0,
|
||||||
out: bool = False,
|
out: bool = False,
|
||||||
fade_in_kwargs: Mapping[str, Any] = {},
|
fade_in_kwargs: Optional[Mapping[str, Any]] = None,
|
||||||
fade_out_kwargs: Mapping[str, Any] = {},
|
fade_out_kwargs: Optional[Mapping[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
scale_in = 1.0 / scale
|
scale_in = 1.0 / scale
|
||||||
@ -134,10 +142,18 @@ class Zoom(AnimationGroup): # type: ignore[misc]
|
|||||||
|
|
||||||
animations = []
|
animations = []
|
||||||
|
|
||||||
for mobject in future:
|
if future:
|
||||||
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
|
if fade_in_kwargs is None:
|
||||||
|
fade_in_kwargs = {}
|
||||||
|
|
||||||
for mobject in current:
|
for mobject in future:
|
||||||
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
|
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
|
||||||
|
|
||||||
|
if current:
|
||||||
|
if fade_out_kwargs is None:
|
||||||
|
fade_out_kwargs = {}
|
||||||
|
|
||||||
|
for mobject in current:
|
||||||
|
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
|
||||||
|
|
||||||
super().__init__(*animations, **kwargs)
|
super().__init__(*animations, **kwargs)
|
||||||
|
Reference in New Issue
Block a user