mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Kill config in transform.py
This commit is contained in:
parent
adf886dced
commit
5571c7d576
2 changed files with 25 additions and 88 deletions
|
@ -5,7 +5,6 @@ import inspect
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME
|
||||
from manimlib.constants import DEGREES
|
||||
from manimlib.constants import OUT
|
||||
from manimlib.mobject.mobject import Group
|
||||
|
@ -26,21 +25,22 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class Transform(Animation):
|
||||
CONFIG = {
|
||||
"path_arc": 0,
|
||||
"path_arc_axis": OUT,
|
||||
"path_func": None,
|
||||
"replace_mobject_with_target_in_scene": False,
|
||||
}
|
||||
replace_mobject_with_target_in_scene: bool = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mobject: Mobject,
|
||||
target_mobject: Mobject | None = None,
|
||||
path_arc: float = 0.0,
|
||||
path_arc_axis: np.ndarray = OUT,
|
||||
path_func: Callable | None = None,
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(mobject, **kwargs)
|
||||
self.target_mobject = target_mobject
|
||||
self.path_arc = path_arc
|
||||
self.path_arc_axis = path_arc_axis
|
||||
self.path_func = path_func
|
||||
super().__init__(mobject, **kwargs)
|
||||
self.init_path_func()
|
||||
|
||||
def init_path_func(self) -> None:
|
||||
|
@ -129,33 +129,14 @@ class Transform(Animation):
|
|||
|
||||
|
||||
class ReplacementTransform(Transform):
|
||||
CONFIG = {
|
||||
"replace_mobject_with_target_in_scene": True,
|
||||
}
|
||||
replace_mobject_with_target_in_scene: bool = True
|
||||
|
||||
|
||||
class TransformFromCopy(Transform):
|
||||
"""
|
||||
Performs a reversed Transform
|
||||
"""
|
||||
replace_mobject_with_target_in_scene: bool = True
|
||||
|
||||
def __init__(self, mobject: Mobject, target_mobject: Mobject, **kwargs):
|
||||
super().__init__(target_mobject, mobject, **kwargs)
|
||||
|
||||
def interpolate(self, alpha: float) -> None:
|
||||
super().interpolate(1 - alpha)
|
||||
|
||||
|
||||
class ClockwiseTransform(Transform):
|
||||
CONFIG = {
|
||||
"path_arc": -np.pi
|
||||
}
|
||||
|
||||
|
||||
class CounterclockwiseTransform(Transform):
|
||||
CONFIG = {
|
||||
"path_arc": np.pi
|
||||
}
|
||||
super().__init__(mobject.copy(), target_mobject, **kwargs)
|
||||
|
||||
|
||||
class MoveToTarget(Transform):
|
||||
|
@ -166,8 +147,7 @@ class MoveToTarget(Transform):
|
|||
def check_validity_of_input(self, mobject: Mobject) -> None:
|
||||
if not hasattr(mobject, "target"):
|
||||
raise Exception(
|
||||
"MoveToTarget called on mobject"
|
||||
"without attribute 'target'"
|
||||
"MoveToTarget called on mobject without attribute 'target'"
|
||||
)
|
||||
|
||||
|
||||
|
@ -215,20 +195,17 @@ class ApplyMethod(Transform):
|
|||
|
||||
|
||||
class ApplyPointwiseFunction(ApplyMethod):
|
||||
CONFIG = {
|
||||
"run_time": DEFAULT_POINTWISE_FUNCTION_RUN_TIME
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
function: Callable[[np.ndarray], np.ndarray],
|
||||
mobject: Mobject,
|
||||
run_time: float = 3.0,
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(mobject.apply_function, function, **kwargs)
|
||||
super().__init__(mobject.apply_function, function, run_time=run_time, **kwargs)
|
||||
|
||||
|
||||
class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
|
||||
class ApplyPointwiseFunctionToCenter(Transform):
|
||||
def __init__(
|
||||
self,
|
||||
function: Callable[[np.ndarray], np.ndarray],
|
||||
|
@ -236,13 +213,10 @@ class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
|
|||
**kwargs
|
||||
):
|
||||
self.function = function
|
||||
super().__init__(mobject.move_to, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def begin(self) -> None:
|
||||
self.method_args = [
|
||||
self.function(self.mobject.get_center())
|
||||
]
|
||||
super().begin()
|
||||
def create_target(self) -> Mobject:
|
||||
return self.mobject.copy().move_to(self.function(self.mobject.get_center()))
|
||||
|
||||
|
||||
class FadeToColor(ApplyMethod):
|
||||
|
@ -339,54 +313,18 @@ class ApplyComplexFunction(ApplyMethod):
|
|||
|
||||
|
||||
class CyclicReplace(Transform):
|
||||
CONFIG = {
|
||||
"path_arc": 90 * DEGREES,
|
||||
}
|
||||
|
||||
def __init__(self, *mobjects: Mobject, **kwargs):
|
||||
self.group = Group(*mobjects)
|
||||
super().__init__(self.group, **kwargs)
|
||||
def __init__(self, *mobjects: Mobject, path_arc=90 * DEGREES, **kwargs):
|
||||
super().__init__(Group(*mobjects), path_arc=path_arc, **kwargs)
|
||||
|
||||
def create_target(self) -> Mobject:
|
||||
target = self.group.copy()
|
||||
group = self.mobject
|
||||
target = group.copy()
|
||||
cycled_targets = [target[-1], *target[:-1]]
|
||||
for m1, m2 in zip(cycled_targets, self.group):
|
||||
for m1, m2 in zip(cycled_targets, group):
|
||||
m1.move_to(m2)
|
||||
return target
|
||||
|
||||
|
||||
class Swap(CyclicReplace):
|
||||
pass # Renaming, more understandable for two entries
|
||||
|
||||
|
||||
# TODO, this may be deprecated...worth reimplementing?
|
||||
class TransformAnimations(Transform):
|
||||
CONFIG = {
|
||||
"rate_func": squish_rate_func(smooth)
|
||||
}
|
||||
|
||||
def __init__(self, start_anim: Animation, end_anim: Animation, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
if "run_time" in kwargs:
|
||||
self.run_time = kwargs.pop("run_time")
|
||||
else:
|
||||
self.run_time = max(start_anim.run_time, end_anim.run_time)
|
||||
for anim in start_anim, end_anim:
|
||||
anim.set_run_time(self.run_time)
|
||||
|
||||
if start_anim.starting_mobject.get_num_points() != end_anim.starting_mobject.get_num_points():
|
||||
start_anim.starting_mobject.align_data_and_family(end_anim.starting_mobject)
|
||||
for anim in start_anim, end_anim:
|
||||
if hasattr(anim, "target_mobject"):
|
||||
anim.starting_mobject.align_data_and_family(anim.target_mobject)
|
||||
|
||||
Transform.__init__(self, start_anim.mobject,
|
||||
end_anim.mobject, **kwargs)
|
||||
# Rewire starting and ending mobjects
|
||||
start_anim.mobject = self.starting_mobject
|
||||
end_anim.mobject = self.target_mobject
|
||||
|
||||
def interpolate(self, alpha: float) -> None:
|
||||
self.start_anim.interpolate(alpha)
|
||||
self.end_anim.interpolate(alpha)
|
||||
Transform.interpolate(self, alpha)
|
||||
"""Alternate name for CyclicReplace"""
|
||||
pass
|
||||
|
|
|
@ -22,7 +22,6 @@ DEFAULT_MOBJECT_TO_MOBJECT_BUFFER = MED_SMALL_BUFF
|
|||
|
||||
|
||||
# All in seconds
|
||||
DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0
|
||||
DEFAULT_WAIT_TIME = 1.0
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue