Kill CONFIG in movement.py

This commit is contained in:
Grant Sanderson 2022-12-14 14:58:25 -08:00
parent 7dcf5eff8e
commit 81615d9f4b

View file

@ -14,15 +14,13 @@ if TYPE_CHECKING:
class Homotopy(Animation): class Homotopy(Animation):
CONFIG = { apply_function_config: dict = dict()
"run_time": 3,
"apply_function_kwargs": {},
}
def __init__( def __init__(
self, self,
homotopy: Callable[[float, float, float, float], Sequence[float]], homotopy: Callable[[float, float, float, float], Sequence[float]],
mobject: Mobject, mobject: Mobject,
run_time: float = 3.0,
**kwargs **kwargs
): ):
""" """
@ -30,13 +28,12 @@ class Homotopy(Animation):
(x, y, z, t) to (x', y', z') (x, y, z, t) to (x', y', z')
""" """
self.homotopy = homotopy self.homotopy = homotopy
super().__init__(mobject, **kwargs) super().__init__(mobject, run_time=run_time, **kwargs)
def function_at_time_t( def function_at_time_t(self, t: float) -> Callable[[np.ndarray], Sequence[float]]:
self, def result(p):
t: float return self.homotopy(*p, t)
) -> Callable[[np.ndarray], Sequence[float]]: return result
return lambda p: self.homotopy(*p, t)
def interpolate_submobject( def interpolate_submobject(
self, self,
@ -47,20 +44,18 @@ class Homotopy(Animation):
submob.match_points(start) submob.match_points(start)
submob.apply_function( submob.apply_function(
self.function_at_time_t(alpha), self.function_at_time_t(alpha),
**self.apply_function_kwargs **self.apply_function_config
) )
class SmoothedVectorizedHomotopy(Homotopy): class SmoothedVectorizedHomotopy(Homotopy):
CONFIG = { apply_function_config: dict = dict(make_smooth=True)
"apply_function_kwargs": {"make_smooth": True},
}
class ComplexHomotopy(Homotopy): class ComplexHomotopy(Homotopy):
def __init__( def __init__(
self, self,
complex_homotopy: Callable[[complex, float], Sequence[float]], complex_homotopy: Callable[[complex, float], complex],
mobject: Mobject, mobject: Mobject,
**kwargs **kwargs
): ):
@ -72,24 +67,30 @@ class ComplexHomotopy(Homotopy):
def homotopy(x, y, z, t): def homotopy(x, y, z, t):
c = complex_homotopy(complex(x, y), t) c = complex_homotopy(complex(x, y), t)
return (c.real, c.imag, z) return (c.real, c.imag, z)
super().__init__(homotopy, mobject, **kwargs) super().__init__(homotopy, mobject, **kwargs)
class PhaseFlow(Animation): class PhaseFlow(Animation):
CONFIG = {
"virtual_time": 1,
"rate_func": linear,
"suspend_mobject_updating": False,
}
def __init__( def __init__(
self, self,
function: Callable[[np.ndarray], np.ndarray], function: Callable[[np.ndarray], np.ndarray],
mobject: Mobject, mobject: Mobject,
virtual_time: float | None = None,
suspend_mobject_updating: bool = False,
rate_func: Callable[[float], float] = linear,
run_time: float =3.0,
**kwargs **kwargs
): ):
self.function = function self.function = function
super().__init__(mobject, **kwargs) self.virtual_time = virtual_time or run_time
super().__init__(
mobject,
rate_func=rate_func,
run_time=run_time,
suspend_mobject_updating=suspend_mobject_updating,
**kwargs
)
def interpolate_mobject(self, alpha: float) -> None: def interpolate_mobject(self, alpha: float) -> None:
if hasattr(self, "last_alpha"): if hasattr(self, "last_alpha"):
@ -101,13 +102,15 @@ class PhaseFlow(Animation):
class MoveAlongPath(Animation): class MoveAlongPath(Animation):
CONFIG = { def __init__(
"suspend_mobject_updating": False, self,
} mobject: Mobject,
path: Mobject,
def __init__(self, mobject: Mobject, path: Mobject, **kwargs): suspend_mobject_updating: bool = False,
**kwargs
):
self.path = path self.path = path
super().__init__(mobject, **kwargs) super().__init__(mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs)
def interpolate_mobject(self, alpha: float) -> None: def interpolate_mobject(self, alpha: float) -> None:
point = self.path.point_from_proportion(alpha) point = self.path.point_from_proportion(alpha)