Kill CONFIG in changing.py

This commit is contained in:
Grant Sanderson 2022-12-15 15:40:56 -08:00
parent a78e2b6ad2
commit 57875875c1

View file

@ -11,22 +11,31 @@ from manimlib.utils.rate_functions import smooth
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Callable
from typing import Callable, List, Tuple, Iterable
from manimlib.constants import ManimColor, np_vector
class AnimatedBoundary(VGroup):
CONFIG = {
"colors": [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
"max_stroke_width": 3,
"cycle_rate": 0.5,
"back_and_forth": True,
"draw_rate_func": smooth,
"fade_rate_func": smooth,
}
def __init__(self, vmobject: VMobject, **kwargs):
def __init__(
self,
vmobject: VMobject,
colors: List[ManimColor] = [BLUE_D, BLUE_B, BLUE_E, GREY_BROWN],
max_stroke_width: float = 3.0,
cycle_rate: float = 0.5,
back_and_forth: bool = True,
draw_rate_func: Callable[[float], float] = smooth,
fade_rate_func: Callable[[float], float] = smooth,
**kwargs
):
super().__init__(**kwargs)
self.vmobject: VMobject = vmobject
self.colors = colors
self.max_stroke_width = max_stroke_width
self.cycle_rate = cycle_rate
self.back_and_forth = back_and_forth
self.draw_rate_func = draw_rate_func
self.fade_rate_func = fade_rate_func
self.boundary_copies: list[VMobject] = [
vmobject.copy().set_style(
stroke_width=0,
@ -86,17 +95,25 @@ class AnimatedBoundary(VGroup):
class TracedPath(VMobject):
CONFIG = {
"stroke_width": 2,
"stroke_color": WHITE,
"time_traced": np.inf,
"fill_opacity": 0,
"time_per_anchor": 1 / 15,
}
def __init__(self, traced_point_func: Callable[[], np.ndarray], **kwargs):
super().__init__(**kwargs)
def __init__(
self,
traced_point_func: Callable[[], np_vector],
time_traced: float = np.inf,
time_per_anchor: float = 1.0 / 15,
stroke_width: float | Iterable[float] = 2.0,
stroke_color: ManimColor = WHITE,
fill_opacity: float = 0.0,
**kwargs
):
super().__init__(
stroke_width=stroke_width,
stroke_color=stroke_color,
fill_opacity=fill_opacity,
**kwargs
)
self.traced_point_func = traced_point_func
self.time_traced = time_traced
self.time_per_anchor = time_per_anchor
self.time: float = 0
self.traced_points: list[np.ndarray] = []
self.add_updater(lambda m, dt: m.update_path(dt))
@ -109,23 +126,15 @@ class TracedPath(VMobject):
if self.time_traced < np.inf:
n_relevant_points = int(self.time_traced / dt + 0.5)
# n_anchors = int(self.time_traced / self.time_per_anchor)
n_tps = len(self.traced_points)
if n_tps < n_relevant_points:
points = self.traced_points + [point] * (n_relevant_points - n_tps)
else:
points = self.traced_points[n_tps - n_relevant_points:]
# points = [
# self.traced_points[max(n_tps - int(alpha * n_relevant_points) - 1, 0)]
# for alpha in np.linspace(1, 0, n_anchors)
# ]
# Every now and then refresh the list
if n_tps > 10 * n_relevant_points:
self.traced_points = self.traced_points[-n_relevant_points:]
else:
# sparseness = max(int(self.time_per_anchor / dt), 1)
# points = self.traced_points[::sparseness]
# points[-1] = self.traced_points[-1]
points = self.traced_points
if points:
@ -136,20 +145,24 @@ class TracedPath(VMobject):
class TracingTail(TracedPath):
CONFIG = {
"stroke_width": (0, 3),
"stroke_opacity": (0, 1),
"stroke_color": WHITE,
"time_traced": 1.0,
}
def __init__(
self,
mobject_or_func: Mobject | Callable[[], np.ndarray],
time_traced: float = 1.0,
stroke_width: float | Iterable[float] = (0, 3),
stroke_opacity: float | Iterable[float] = (0, 1),
stroke_color: ManimColor = WHITE,
**kwargs
):
if isinstance(mobject_or_func, Mobject):
func = mobject_or_func.get_center
else:
func = mobject_or_func
super().__init__(func, **kwargs)
super().__init__(
func,
time_traced=time_traced,
stroke_width=stroke_width,
stroke_opacity=stroke_opacity,
stroke_color=stroke_color,
**kwargs
)