mirror of
https://github.com/3b1b/manim.git
synced 2026-04-26 03:00:23 -04:00
Minor cleanup to animation/update.py
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import operator as op
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.constants import *
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
|
||||
|
||||
class UpdateFromFunc(Animation):
|
||||
@@ -9,10 +9,13 @@ class UpdateFromFunc(Animation):
|
||||
to be used when the state of one mobject is dependent
|
||||
on another simultaneously animated mobject
|
||||
"""
|
||||
CONFIG = {
|
||||
"suspend_mobject_updating": False,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, update_function, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
self.update_function = update_function
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def interpolate_mobject(self, alpha):
|
||||
self.update_function(self.mobject)
|
||||
@@ -24,18 +27,15 @@ class UpdateFromAlphaFunc(UpdateFromFunc):
|
||||
|
||||
|
||||
class MaintainPositionRelativeTo(Animation):
|
||||
CONFIG = {
|
||||
"tracked_critical_point": ORIGIN
|
||||
}
|
||||
|
||||
def __init__(self, mobject, tracked_mobject, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
tcp = self.tracked_critical_point
|
||||
self.diff = mobject.get_critical_point(tcp) - \
|
||||
tracked_mobject.get_critical_point(tcp)
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
self.tracked_mobject = tracked_mobject
|
||||
self.diff = op.sub(
|
||||
mobject.get_center(),
|
||||
tracked_mobject.get_center(),
|
||||
)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def interpolate_mobject(self, alpha):
|
||||
target = self.tracked_mobject.get_critical_point(self.tracked_critical_point)
|
||||
location = self.mobject.get_critical_point(self.tracked_critical_point)
|
||||
target = self.tracked_mobject.get_center()
|
||||
location = self.mobject.get_center()
|
||||
self.mobject.shift(target - location + self.diff)
|
||||
|
||||
Reference in New Issue
Block a user