2015-06-10 22:00:35 -07:00
|
|
|
import numpy as np
|
|
|
|
import itertools as it
|
|
|
|
|
|
|
|
from helpers import *
|
|
|
|
|
2015-10-27 21:00:50 -07:00
|
|
|
from animation import Animation
|
|
|
|
from meta_animations import DelayByOrder
|
|
|
|
from transform import Transform
|
2015-08-08 20:42:34 -07:00
|
|
|
|
|
|
|
|
2015-06-10 22:00:35 -07:00
|
|
|
class Rotating(Animation):
|
2015-09-28 16:25:18 -07:00
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
"axes" : [RIGHT, UP],
|
|
|
|
"radians" : 2*np.pi,
|
|
|
|
"run_time" : 20.0,
|
|
|
|
"alpha_func" : None,
|
|
|
|
}
|
2015-06-10 22:00:35 -07:00
|
|
|
def update_mobject(self, alpha):
|
|
|
|
self.mobject.points = self.starting_mobject.points
|
|
|
|
for axis in self.axes:
|
2015-09-28 16:25:18 -07:00
|
|
|
self.mobject.rotate(self.radians * alpha, axis)
|
2015-06-10 22:00:35 -07:00
|
|
|
|
|
|
|
class FadeOut(Animation):
|
|
|
|
def update_mobject(self, alpha):
|
|
|
|
self.mobject.rgbs = self.starting_mobject.rgbs * (1 - alpha)
|
|
|
|
|
|
|
|
class FadeIn(Animation):
|
|
|
|
def update_mobject(self, alpha):
|
|
|
|
self.mobject.rgbs = self.starting_mobject.rgbs * alpha
|
|
|
|
if self.mobject.points.shape != self.starting_mobject.points.shape:
|
|
|
|
self.mobject.points = self.starting_mobject.points
|
|
|
|
#TODO, Why do you need to do this? Shouldn't points always align?
|
|
|
|
|
2015-08-12 14:24:36 -07:00
|
|
|
class ShimmerIn(DelayByOrder):
|
2015-09-28 16:25:18 -07:00
|
|
|
def __init__(self, mobject, **kwargs):
|
2015-08-12 14:24:36 -07:00
|
|
|
mobject.sort_points(lambda p : np.dot(p, DOWN+RIGHT))
|
2015-09-28 16:25:18 -07:00
|
|
|
DelayByOrder.__init__(self, FadeIn(mobject, **kwargs))
|
2015-08-12 14:24:36 -07:00
|
|
|
|
2015-08-08 20:42:34 -07:00
|
|
|
|
2015-06-10 22:00:35 -07:00
|
|
|
class ShowCreation(Animation):
|
|
|
|
def update_mobject(self, alpha):
|
|
|
|
#TODO, shoudl I make this more efficient?
|
|
|
|
new_num_points = int(alpha * self.starting_mobject.points.shape[0])
|
|
|
|
for attr in ["points", "rgbs"]:
|
|
|
|
setattr(
|
|
|
|
self.mobject,
|
|
|
|
attr,
|
|
|
|
getattr(self.starting_mobject, attr)[:new_num_points, :]
|
|
|
|
)
|
|
|
|
|
|
|
|
class Flash(Animation):
|
2015-09-28 16:25:18 -07:00
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
"color" : "white",
|
|
|
|
"slow_factor" : 0.01,
|
|
|
|
"run_time" : 0.1,
|
|
|
|
"alpha_func" : None,
|
|
|
|
}
|
|
|
|
def __init__(self, mobject, **kwargs):
|
|
|
|
self.intermediate = Mobject(color = self.color)
|
2015-06-10 22:00:35 -07:00
|
|
|
self.intermediate.add_points([
|
|
|
|
point + (x, y, 0)
|
|
|
|
for point in self.mobject.points
|
|
|
|
for x in [-1, 1]
|
|
|
|
for y in [-1, 1]
|
|
|
|
])
|
2015-09-28 16:25:18 -07:00
|
|
|
Animation.__init__(self, mobject, **kwargs)
|
2015-06-10 22:00:35 -07:00
|
|
|
|
|
|
|
def update_mobject(self, alpha):
|
|
|
|
#Makes alpha go from 0 to slow_factor to 0 instead of 0 to 1
|
|
|
|
alpha = self.slow_factor * (1.0 - 4 * (alpha - 0.5)**2)
|
2015-11-02 14:09:49 -08:00
|
|
|
self.mobject.interpolate(
|
2015-06-10 22:00:35 -07:00
|
|
|
self.starting_mobject,
|
|
|
|
self.intermediate,
|
|
|
|
alpha
|
|
|
|
)
|
|
|
|
|
|
|
|
class Homotopy(Animation):
|
2015-10-28 16:03:33 -07:00
|
|
|
def __init__(self, homotopy, mobject, **kwargs):
|
2015-06-10 22:00:35 -07:00
|
|
|
"""
|
|
|
|
Homotopy a function from (x, y, z, t) to (x', y', z')
|
|
|
|
"""
|
2015-10-28 16:03:33 -07:00
|
|
|
digest_locals(self)
|
|
|
|
Animation.__init__(self, mobject, **kwargs)
|
2015-06-10 22:00:35 -07:00
|
|
|
|
|
|
|
def update_mobject(self, alpha):
|
|
|
|
self.mobject.points = np.array([
|
|
|
|
self.homotopy((x, y, z, alpha))
|
|
|
|
for x, y, z in self.starting_mobject.points
|
|
|
|
])
|
|
|
|
|
2015-06-19 08:31:02 -07:00
|
|
|
|
2015-06-10 22:00:35 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|