2018-03-31 15:37:23 -07:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from continual_animation.continual_animation import ContinualAnimation
|
|
|
|
from animation.update import MaintainPositionRelativeTo
|
|
|
|
|
|
|
|
|
|
|
|
class ContinualUpdateFromFunc(ContinualAnimation):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"function_depends_on_dt": False
|
2018-03-31 15:37:23 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:37:23 -07:00
|
|
|
def __init__(self, mobject, func, **kwargs):
|
|
|
|
self.func = func
|
|
|
|
ContinualAnimation.__init__(self, mobject, **kwargs)
|
|
|
|
|
|
|
|
def update_mobject(self, dt):
|
|
|
|
if self.function_depends_on_dt:
|
|
|
|
self.func(self.mobject, dt)
|
|
|
|
else:
|
|
|
|
self.func(self.mobject)
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:37:23 -07:00
|
|
|
class ContinualUpdateFromTimeFunc(ContinualUpdateFromFunc):
|
|
|
|
CONFIG = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"function_depends_on_dt": True
|
2018-03-31 15:37:23 -07:00
|
|
|
}
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 15:37:23 -07:00
|
|
|
class ContinualMaintainPositionRelativeTo(ContinualAnimation):
|
|
|
|
# TODO: Possibly reimplement using CycleAnimation?
|
|
|
|
def __init__(self, mobject, tracked_mobject, **kwargs):
|
2018-04-06 13:58:59 -07:00
|
|
|
self.anim = MaintainPositionRelativeTo(
|
|
|
|
mobject, tracked_mobject, **kwargs)
|
2018-03-31 15:37:23 -07:00
|
|
|
ContinualAnimation.__init__(self, mobject, **kwargs)
|
|
|
|
|
|
|
|
def update_mobject(self, dt):
|
2018-04-06 13:58:59 -07:00
|
|
|
self.anim.update(0) # 0 is arbitrary
|