Added/tweaked some indication animations

This commit is contained in:
Grant Sanderson
2018-05-07 13:33:06 -07:00
parent 4403399050
commit 99d119e1f6

View File

@ -6,14 +6,21 @@ from constants import *
from animation.animation import Animation
from animation.movement import Homotopy
from animation.composition import AnimationGroup
from animation.composition import Succession
from animation.creation import ShowCreation
from animation.creation import ShowPartial
from animation.creation import FadeOut
from animation.transform import Transform
from mobject.mobject import Mobject
from mobject.geometry import Circle
from mobject.geometry import Dot
from mobject.shape_matchers import SurroundingRectangle
from utils.bezier import interpolate
from utils.config_ops import digest_config
from utils.rate_functions import squish_rate_func
from utils.rate_functions import there_and_back
from utils.rate_functions import wiggle
class FocusOn(Transform):
@ -93,14 +100,49 @@ class ShowCreationThenDestruction(ShowPassingFlash):
}
class AnimationOnSurroundingRectangle(AnimationGroup):
CONFIG = {
"surrounding_rectangle_config": {},
# Function which takes in a rectangle, and spits
# out some animation. Could be some animation class,
# could be something more
"rect_to_animation": Animation
}
def __init__(self, mobject, **kwargs):
digest_config(self, kwargs)
rect = SurroundingRectangle(
mobject, **self.surrounding_rectangle_config
)
AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
class ShowPassingFlashAround(AnimationOnSurroundingRectangle):
CONFIG = {
"rect_to_animation": ShowPassingFlash
}
class ShowCreationThenDestructionAround(AnimationOnSurroundingRectangle):
CONFIG = {
"rect_to_animation": ShowCreationThenDestruction
}
class CircleThenFadeAround(AnimationOnSurroundingRectangle):
CONFIG = {
"rect_to_animation": lambda rect: Succession(
ShowCreation, rect,
FadeOut, rect,
)
}
class ApplyWave(Homotopy):
CONFIG = {
"direction": DOWN,
"direction": UP,
"amplitude": 0.2,
"run_time": 1,
"apply_function_kwargs": {
"maintain_smoothness": False,
},
}
def __init__(self, mobject, **kwargs):
@ -110,9 +152,9 @@ class ApplyWave(Homotopy):
vect = self.amplitude * self.direction
def homotopy(x, y, z, t):
start_point = np.array([x, y, z])
alpha = (x - left_x) / (right_x - left_x)
power = np.exp(2 * (alpha - 0.5))
# lf = self.lag_factor
power = np.exp(2.0 * (alpha - 0.5))
nudge = there_and_back(t**power)
return np.array([x, y, z]) + nudge * vect
Homotopy.__init__(self, homotopy, mobject, **kwargs)
@ -195,7 +237,6 @@ class TurnInsideOut(Transform):
}
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))
mob_copy.reverse_points()
Transform.__init__(self, mobject, mob_copy, **kwargs)