mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 21:44:19 +08:00
Reorganized animations folder. Warning: While I tried to be systematic, there is a decent chance this will cause import errors somewhere.
This commit is contained in:
62
animation/movement.py
Normal file
62
animation/movement.py
Normal file
@ -0,0 +1,62 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from constants import *
|
||||
|
||||
import warnings
|
||||
|
||||
from animation.animation import Animation
|
||||
from utils.config_ops import digest_config
|
||||
|
||||
class Homotopy(Animation):
|
||||
CONFIG = {
|
||||
"run_time" : 3,
|
||||
"apply_function_kwargs" : {},
|
||||
}
|
||||
def __init__(self, homotopy, mobject, **kwargs):
|
||||
"""
|
||||
Homotopy a function from (x, y, z, t) to (x', y', z')
|
||||
"""
|
||||
def function_at_time_t(t):
|
||||
return lambda p : homotopy(p[0], p[1], p[2], t)
|
||||
self.function_at_time_t = function_at_time_t
|
||||
digest_config(self, kwargs)
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_submobject(self, submob, start, alpha):
|
||||
submob.points = start.points
|
||||
submob.apply_function(
|
||||
self.function_at_time_t(alpha),
|
||||
**self.apply_function_kwargs
|
||||
)
|
||||
|
||||
class SmoothedVectorizedHomotopy(Homotopy):
|
||||
def update_submobject(self, submob, start, alpha):
|
||||
Homotopy.update_submobject(self, submob, start, alpha)
|
||||
submob.make_smooth()
|
||||
|
||||
class PhaseFlow(Animation):
|
||||
CONFIG = {
|
||||
"virtual_time" : 1,
|
||||
"rate_func" : None,
|
||||
}
|
||||
def __init__(self, function, mobject, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
if hasattr(self, "last_alpha"):
|
||||
dt = self.virtual_time*(alpha-self.last_alpha)
|
||||
self.mobject.apply_function(
|
||||
lambda p : p + dt*self.function(p)
|
||||
)
|
||||
self.last_alpha = alpha
|
||||
|
||||
class MoveAlongPath(Animation):
|
||||
def __init__(self, mobject, path, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
point = self.path.point_from_proportion(alpha)
|
||||
self.mobject.move_to(point)
|
||||
|
Reference in New Issue
Block a user