3b1b-manim/manimlib/animation/update.py
Grant Sanderson e5298385ed
Video work (#2402)
* Bug fix for TransformMatchingStrings with incompatible lengths

* Change faded line in NumberPlane initialization to be more explicit, and lower opacity

* Add option hide_zero_components_on_complex to DecimalNumber

* Validate syntax before reloading

* Add remembered stroke_config to TracedPath

* Add CLAUDE.md to gitignore

* Move pre-calculated traced points to TracingTail

* Fix interplay between time_span and alpha in Animation

* Clearer init for points in TracingTail

* Fix CoordinateSystem.get_area_under_graph

* Allow ComplexPlane.n2p to take in array of complex numbers

* Add put_start_on and put_end_on

* Add Slider

* Add \minus option for Tex to give shorter negative sign

* Put interp_by_hsl option in various color interpretation functions

* Swap priority of matched_keys vs key_map is TransformMatchingStrings

* Have z-index apply recursively

* Set self.svg_string property for SVGMobject

* Fix num_decimal_places config in Tex.make_number_changeable

* Add Surface. color_by_uv_function

* Add VMobject. set_color_by_proportion

* Add \mathcal to tex_to_symbol_count
2025-10-14 07:15:39 -07:00

67 lines
2 KiB
Python

from __future__ import annotations
from manimlib.animation.animation import Animation
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Callable
from manimlib.mobject.mobject import Mobject
class UpdateFromFunc(Animation):
"""
update_function of the form func(mobject), presumably
to be used when the state of one mobject is dependent
on another simultaneously animated mobject
"""
def __init__(
self,
mobject: Mobject,
update_function: Callable[[Mobject], Mobject | None],
suspend_mobject_updating: bool = False,
**kwargs
):
self.update_function = update_function
super().__init__(
mobject,
suspend_mobject_updating=suspend_mobject_updating,
**kwargs
)
def interpolate_mobject(self, alpha: float) -> None:
self.update_function(self.mobject)
class UpdateFromAlphaFunc(Animation):
def __init__(
self,
mobject: Mobject,
update_function: Callable[[Mobject, float], Mobject | None],
suspend_mobject_updating: bool = False,
**kwargs
):
self.update_function = update_function
super().__init__(mobject, suspend_mobject_updating=suspend_mobject_updating, **kwargs)
def interpolate_mobject(self, alpha: float) -> None:
true_alpha = self.rate_func(self.time_spanned_alpha(alpha))
self.update_function(self.mobject, true_alpha)
class MaintainPositionRelativeTo(Animation):
def __init__(
self,
mobject: Mobject,
tracked_mobject: Mobject,
**kwargs
):
self.tracked_mobject = tracked_mobject
self.diff = mobject.get_center() - tracked_mobject.get_center()
super().__init__(mobject, **kwargs)
def interpolate_mobject(self, alpha: float) -> None:
target = self.tracked_mobject.get_center()
location = self.mobject.get_center()
self.mobject.shift(target - location + self.diff)