2019-02-10 10:43:45 -08:00
|
|
|
import operator as op
|
|
|
|
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.animation.animation import Animation
|
2018-03-31 15:11:35 -07:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2019-02-10 10:43:45 -08:00
|
|
|
CONFIG = {
|
|
|
|
"suspend_mobject_updating": False,
|
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:11:35 -07:00
|
|
|
def __init__(self, mobject, update_function, **kwargs):
|
2019-02-10 10:43:45 -08:00
|
|
|
self.update_function = update_function
|
|
|
|
super().__init__(mobject, **kwargs)
|
2018-03-31 15:11:35 -07:00
|
|
|
|
2019-02-08 11:57:27 -08:00
|
|
|
def interpolate_mobject(self, alpha):
|
2018-03-31 15:11:35 -07:00
|
|
|
self.update_function(self.mobject)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:11:35 -07:00
|
|
|
class UpdateFromAlphaFunc(UpdateFromFunc):
|
2019-02-08 11:57:27 -08:00
|
|
|
def interpolate_mobject(self, alpha):
|
2018-03-31 15:11:35 -07:00
|
|
|
self.update_function(self.mobject, alpha)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:11:35 -07:00
|
|
|
class MaintainPositionRelativeTo(Animation):
|
|
|
|
def __init__(self, mobject, tracked_mobject, **kwargs):
|
2019-02-10 10:43:45 -08:00
|
|
|
self.tracked_mobject = tracked_mobject
|
|
|
|
self.diff = op.sub(
|
|
|
|
mobject.get_center(),
|
|
|
|
tracked_mobject.get_center(),
|
|
|
|
)
|
|
|
|
super().__init__(mobject, **kwargs)
|
2018-03-31 15:11:35 -07:00
|
|
|
|
2019-02-08 11:57:27 -08:00
|
|
|
def interpolate_mobject(self, alpha):
|
2019-02-10 10:43:45 -08:00
|
|
|
target = self.tracked_mobject.get_center()
|
|
|
|
location = self.mobject.get_center()
|
2018-12-27 09:41:41 -08:00
|
|
|
self.mobject.shift(target - location + self.diff)
|