2015-12-15 11:31:19 -08:00
|
|
|
import numpy as np
|
2015-12-20 16:43:22 -08:00
|
|
|
import operator as op
|
2015-12-15 11:31:19 -08:00
|
|
|
|
2018-03-30 18:42:32 -07:00
|
|
|
from .animation import Animation
|
2015-12-15 11:31:19 -08:00
|
|
|
from transform import Transform
|
2018-03-30 18:42:32 -07:00
|
|
|
from mobject.mobject import Mobject
|
|
|
|
from mobject.point_cloud_mobject import Mobject1D
|
2015-12-20 16:43:22 -08:00
|
|
|
from topics.geometry import Line
|
2018-03-30 18:19:23 -07:00
|
|
|
from utils.paths import path_along_arc
|
2015-12-15 11:31:19 -08:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
from constants import *
|
2015-12-15 11:31:19 -08:00
|
|
|
|
2015-12-20 16:43:22 -08:00
|
|
|
class Vibrate(Animation):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2015-12-20 16:43:22 -08:00
|
|
|
"spatial_period" : 6,
|
|
|
|
"temporal_period" : 1,
|
|
|
|
"overtones" : 4,
|
|
|
|
"amplitude" : 0.5,
|
2018-03-30 11:25:37 -07:00
|
|
|
"radius" : FRAME_X_RADIUS/2,
|
2015-12-20 16:43:22 -08:00
|
|
|
"run_time" : 3.0,
|
2016-01-01 14:51:16 -08:00
|
|
|
"rate_func" : None
|
2015-12-15 11:31:19 -08:00
|
|
|
}
|
2015-12-20 16:43:22 -08:00
|
|
|
def __init__(self, mobject = None, **kwargs):
|
|
|
|
if mobject is None:
|
|
|
|
mobject = Line(3*LEFT, 3*RIGHT)
|
|
|
|
Animation.__init__(self, mobject, **kwargs)
|
|
|
|
|
|
|
|
def wave_function(self, x, t):
|
|
|
|
return sum([
|
|
|
|
reduce(op.mul, [
|
|
|
|
self.amplitude/(k**2), #Amplitude
|
|
|
|
np.sin(2*np.pi*(k**1.5)*t/self.temporal_period), #Frequency
|
|
|
|
np.sin(2*np.pi*k*x/self.spatial_period) #Number of waves
|
2015-12-15 11:31:19 -08:00
|
|
|
])
|
2015-12-20 16:43:22 -08:00
|
|
|
for k in range(1, self.overtones+1)
|
|
|
|
])
|
|
|
|
|
2015-12-15 11:31:19 -08:00
|
|
|
|
|
|
|
def update_mobject(self, alpha):
|
2015-12-20 16:43:22 -08:00
|
|
|
time = alpha*self.run_time
|
|
|
|
families = map(
|
2015-12-22 11:02:58 -08:00
|
|
|
Mobject.submobject_family,
|
2015-12-20 16:43:22 -08:00
|
|
|
[self.mobject, self.starting_mobject]
|
|
|
|
)
|
|
|
|
for mob, start in zip(*families):
|
|
|
|
mob.points = np.apply_along_axis(
|
|
|
|
lambda (x, y, z) : (x, y + self.wave_function(x, time), z),
|
|
|
|
1, start.points
|
|
|
|
)
|
2015-12-15 11:31:19 -08:00
|
|
|
|
|
|
|
|
|
|
|
class TurnInsideOut(Transform):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2016-01-01 14:51:16 -08:00
|
|
|
"path_func" : path_along_arc(np.pi/2)
|
2015-12-15 11:31:19 -08:00
|
|
|
}
|
|
|
|
def __init__(self, mobject, **kwargs):
|
|
|
|
mobject.sort_points(np.linalg.norm)
|
|
|
|
mob_copy = mobject.copy()
|
|
|
|
mob_copy.sort_points(lambda p : -np.linalg.norm(p))
|
|
|
|
Transform.__init__(self, mobject, mob_copy, **kwargs)
|
|
|
|
|
|
|
|
|