mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Reorganized continual_animation folder
This commit is contained in:
parent
087f66aca5
commit
846bd1065c
13 changed files with 93 additions and 82 deletions
|
@ -29,6 +29,8 @@ from camera.moving_camera import *
|
|||
from camera.mapping_camera import *
|
||||
|
||||
from continual_animation.continual_animation import *
|
||||
from continual_animation.from_animation import *
|
||||
from continual_animation.update import *
|
||||
|
||||
from mobject.image_mobject import *
|
||||
from mobject.mobject import *
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from constants import *
|
||||
from mobject.mobject import Mobject, Group
|
||||
from animation.update import MaintainPositionRelativeTo
|
||||
import copy
|
||||
from utils.config_ops import instantiate
|
||||
|
||||
from constants import *
|
||||
from mobject.mobject import Group
|
||||
from mobject.mobject import Mobject
|
||||
from utils.config_ops import digest_config
|
||||
from utils.config_ops import instantiate
|
||||
|
||||
class ContinualAnimation(object):
|
||||
CONFIG = {
|
||||
|
@ -66,7 +67,7 @@ class ContinualAnimationGroup(ContinualAnimation):
|
|||
for continual_animation in self.continual_animations:
|
||||
continual_animation.update(dt)
|
||||
|
||||
class AmbientRotation(ContinualAnimation):
|
||||
class ContinualRotation(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"axis" : OUT,
|
||||
"rate" : np.pi/12, #Radians per second
|
||||
|
@ -86,7 +87,7 @@ class AmbientRotation(ContinualAnimation):
|
|||
about_point = about_point
|
||||
)
|
||||
|
||||
class AmbientMovement(ContinualAnimation):
|
||||
class ContinualMovement(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"direction" : RIGHT,
|
||||
"rate" : 0.05, #Units per second
|
||||
|
@ -95,59 +96,6 @@ class AmbientMovement(ContinualAnimation):
|
|||
def update_mobject(self, dt):
|
||||
self.mobject.shift(dt*self.rate*self.direction)
|
||||
|
||||
class ContinualUpdateFromFunc(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"function_depends_on_dt" : False
|
||||
}
|
||||
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)
|
||||
|
||||
class ContinualUpdateFromTimeFunc(ContinualUpdateFromFunc):
|
||||
CONFIG = {
|
||||
"function_depends_on_dt" : True
|
||||
}
|
||||
|
||||
class ContinualMaintainPositionRelativeTo(ContinualAnimation):
|
||||
# TODO: Possibly reimplement using CycleAnimation?
|
||||
def __init__(self, mobject, tracked_mobject, **kwargs):
|
||||
self.anim = MaintainPositionRelativeTo(mobject, tracked_mobject, **kwargs)
|
||||
ContinualAnimation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
self.anim.update(0) # 0 is arbitrary
|
||||
|
||||
class NormalAnimationAsContinualAnimation(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"start_up_time" : 0,
|
||||
"wind_down_time" : 0,
|
||||
}
|
||||
def __init__(self, animation, **kwargs):
|
||||
self.animation = animation
|
||||
ContinualAnimation.__init__(self, animation.mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
self.animation.update(
|
||||
min(float(self.internal_time)/self.animation.run_time, 1)
|
||||
)
|
||||
|
||||
class CycleAnimation(ContinualAnimation):
|
||||
def __init__(self, animation, **kwargs):
|
||||
self.animation = animation
|
||||
ContinualAnimation.__init__(self, animation.mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
mod_value = self.internal_time % self.animation.run_time
|
||||
alpha = mod_value/float(self.animation.run_time)
|
||||
self.animation.update(alpha)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
28
continual_animation/from_animation.py
Normal file
28
continual_animation/from_animation.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from continual_animation.continual_animation import ContinualAnimation
|
||||
|
||||
class NormalAnimationAsContinualAnimation(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"start_up_time" : 0,
|
||||
"wind_down_time" : 0,
|
||||
}
|
||||
def __init__(self, animation, **kwargs):
|
||||
self.animation = animation
|
||||
ContinualAnimation.__init__(self, animation.mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
self.animation.update(
|
||||
min(float(self.internal_time)/self.animation.run_time, 1)
|
||||
)
|
||||
|
||||
class CycleAnimation(ContinualAnimation):
|
||||
def __init__(self, animation, **kwargs):
|
||||
self.animation = animation
|
||||
ContinualAnimation.__init__(self, animation.mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
mod_value = self.internal_time % self.animation.run_time
|
||||
alpha = mod_value/float(self.animation.run_time)
|
||||
self.animation.update(alpha)
|
||||
|
33
continual_animation/update.py
Normal file
33
continual_animation/update.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from continual_animation.continual_animation import ContinualAnimation
|
||||
from animation.update import MaintainPositionRelativeTo
|
||||
|
||||
|
||||
class ContinualUpdateFromFunc(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"function_depends_on_dt" : False
|
||||
}
|
||||
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)
|
||||
|
||||
class ContinualUpdateFromTimeFunc(ContinualUpdateFromFunc):
|
||||
CONFIG = {
|
||||
"function_depends_on_dt" : True
|
||||
}
|
||||
|
||||
class ContinualMaintainPositionRelativeTo(ContinualAnimation):
|
||||
# TODO: Possibly reimplement using CycleAnimation?
|
||||
def __init__(self, mobject, tracked_mobject, **kwargs):
|
||||
self.anim = MaintainPositionRelativeTo(mobject, tracked_mobject, **kwargs)
|
||||
ContinualAnimation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
self.anim.update(0) # 0 is arbitrary
|
|
@ -7,8 +7,9 @@ import os
|
|||
from PIL import Image
|
||||
from random import random
|
||||
|
||||
from mobject.mobject import Mobject
|
||||
from constants import *
|
||||
|
||||
from mobject.mobject import Mobject
|
||||
from mobject.point_cloud_mobject import PMobject
|
||||
from utils.bezier import interpolate
|
||||
from utils.color import color_to_int_rgb
|
||||
|
|
|
@ -8,7 +8,8 @@ from utils.iterables import adjacent_pairs
|
|||
|
||||
from constants import *
|
||||
|
||||
#TODO, this whole class should be something vectorized.
|
||||
# Warning: This is all now pretty depricated, and should not be expected to work
|
||||
|
||||
class Region(Mobject):
|
||||
CONFIG = {
|
||||
"display_mode" : "region"
|
||||
|
|
|
@ -231,8 +231,6 @@ class SVGMobject(VMobject):
|
|||
if self.width is not None:
|
||||
self.scale_to_fit_width(self.width)
|
||||
|
||||
|
||||
|
||||
class VMobjectFromSVGPathstring(VMobject):
|
||||
def __init__(self, path_string, **kwargs):
|
||||
digest_locals(self)
|
||||
|
|
|
@ -1146,7 +1146,7 @@ class TwoDScreenInOurThreeDWorld(AltTeacherStudentsScene, ThreeDScene):
|
|||
run_time = 4,
|
||||
added_anims = [MoveToTarget(everything, run_time = 4)],
|
||||
)
|
||||
self.add(AmbientRotation(everything, axis = UP, rate = 3*DEGREES))
|
||||
self.add(ContinualRotation(everything, axis = UP, rate = 3*DEGREES))
|
||||
self.wait(10)
|
||||
|
||||
class EveryOutputPointHasAColor(ColorMappedObjectsScene):
|
||||
|
@ -3188,7 +3188,7 @@ class PatreonScroll(Scene):
|
|||
|
||||
# patorons = patrons[:10] ##TO remove
|
||||
|
||||
scroll = AmbientMovement(patrons, direction = UP, rate = 1)
|
||||
scroll = ContinualMovement(patrons, direction = UP, rate = 1)
|
||||
def patrons_opacity_update(patrons):
|
||||
for patron in patrons:
|
||||
y = patron.get_center()[1]
|
||||
|
|
|
@ -3848,7 +3848,7 @@ class ThinkBackToHowAmazingThisIs(ThreeDScene):
|
|||
for n in range(0, self.max_shown_n, 2)
|
||||
])
|
||||
|
||||
zoom_out = AmbientMovement(
|
||||
zoom_out = ContinualMovement(
|
||||
self.camera.rotation_mobject,
|
||||
direction = OUT, rate = 0.4
|
||||
)
|
||||
|
|
|
@ -2874,7 +2874,7 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot):
|
|||
self.wait()
|
||||
|
||||
ghost_dot.move_to(ORIGIN)
|
||||
ambient_ghost_dot_movement = AmbientMovement(
|
||||
ambient_ghost_dot_movement = ContinualMovement(
|
||||
ghost_dot, rate = TAU
|
||||
)
|
||||
self.add(ambient_ghost_dot_movement)
|
||||
|
@ -2896,7 +2896,7 @@ class WriteComplexExponentialExpression(DrawFrequencyPlot):
|
|||
)
|
||||
)
|
||||
ghost_dot.move_to(ORIGIN)
|
||||
ambient_ghost_dot_movement = AmbientMovement(
|
||||
ambient_ghost_dot_movement = ContinualMovement(
|
||||
ghost_dot, rate = 0.1*TAU
|
||||
)
|
||||
self.add(ambient_ghost_dot_movement)
|
||||
|
|
|
@ -288,7 +288,7 @@ class AboutToyPuzzles(UtilitiesPuzzleScene, TeacherStudentsScene, ThreeDScene):
|
|||
eulers.get_bottom(),
|
||||
color = WHITE
|
||||
)
|
||||
self.add(AmbientRotation(cube, axis = UP))
|
||||
self.add(ContinualRotation(cube, axis = UP))
|
||||
self.play(
|
||||
GrowArrow(arrow_to_eulers),
|
||||
Write(eulers),
|
||||
|
@ -1884,7 +1884,7 @@ class EulersFormulaForGeneralPlanarGraph(LightUpNodes, ThreeDScene):
|
|||
self.play(FadeOut(self.vertices))
|
||||
self.play(ReplacementTransform(regions, cube, run_time = 2))
|
||||
cube.sort_submobjects(lambda p : -p[2])
|
||||
self.add(AmbientRotation(cube, axis = UP, in_place = False))
|
||||
self.add(ContinualRotation(cube, axis = UP, in_place = False))
|
||||
self.wait(3)
|
||||
self.play(
|
||||
FadeOut(self.top_formula),
|
||||
|
|
|
@ -608,7 +608,7 @@ class ShowPlan(PiCreatureScene):
|
|||
rect = BackgroundRectangle(wave, fill_opacity = 1)
|
||||
rect.stretch(2, 1)
|
||||
rect.next_to(wave, LEFT, buff = 0)
|
||||
wave_shift = AmbientMovement(
|
||||
wave_shift = ContinualMovement(
|
||||
wave, direction = LEFT, rate = 5
|
||||
)
|
||||
wave_fader = UpdateFromAlphaFunc(
|
||||
|
@ -644,7 +644,7 @@ class ShowPlan(PiCreatureScene):
|
|||
target = Plane()
|
||||
# target.match_height(radar_dish)
|
||||
target.next_to(radar_dish, RIGHT, buff = LARGE_BUFF)
|
||||
target_movement = AmbientMovement(target, direction = RIGHT, rate = 1.25)
|
||||
target_movement = ContinualMovement(target, direction = RIGHT, rate = 1.25)
|
||||
|
||||
pulse = RadarPulse(radar_dish, target)
|
||||
|
||||
|
@ -1730,7 +1730,7 @@ class MentionDopplerRadar(TeacherStudentsScene):
|
|||
plane = Plane()
|
||||
plane.to_edge(RIGHT)
|
||||
plane.align_to(dish)
|
||||
plane_flight = AmbientMovement(
|
||||
plane_flight = ContinualMovement(
|
||||
plane,
|
||||
direction = LEFT,
|
||||
rate = 1,
|
||||
|
@ -1911,7 +1911,7 @@ class IntroduceDopplerRadar(Scene):
|
|||
ShowCreation(sum_graph, run_time = 8, rate_func = None)
|
||||
)
|
||||
pulse = RadarPulse(dish, plane, n_pulse_singletons = 12)
|
||||
plane_flight = AmbientMovement(
|
||||
plane_flight = ContinualMovement(
|
||||
plane, direction = LEFT, rate = 1.5
|
||||
)
|
||||
|
||||
|
@ -2690,7 +2690,7 @@ class AmbiguityInLongEchos(IntroduceDopplerRadar, PiCreatureScene):
|
|||
object_velocities = self.object_velocities
|
||||
|
||||
movements = self.object_movements = [
|
||||
AmbientMovement(
|
||||
ContinualMovement(
|
||||
obj,
|
||||
direction = v/np.linalg.norm(v),
|
||||
rate = np.linalg.norm(v)
|
||||
|
@ -3366,7 +3366,7 @@ class SortOfDopplerEffect(PiCreatureScene):
|
|||
t_tracker = VectorizedPoint()
|
||||
#x-coordinate gives wave number
|
||||
k_tracker = VectorizedPoint(2*RIGHT)
|
||||
tk_movement = AmbientMovement(t_tracker, direction = RIGHT, rate = 1)
|
||||
tk_movement = ContinualMovement(t_tracker, direction = RIGHT, rate = 1)
|
||||
def get_wave():
|
||||
t = t_tracker.get_center()[0]
|
||||
k = k_tracker.get_center()[0]
|
||||
|
@ -3399,7 +3399,7 @@ class SortOfDopplerEffect(PiCreatureScene):
|
|||
|
||||
rect = ScreenRectangle(height = 2)
|
||||
rect.to_edge(RIGHT)
|
||||
rect_movement = AmbientMovement(rect, direction = LEFT, rate = 1)
|
||||
rect_movement = ContinualMovement(rect, direction = LEFT, rate = 1)
|
||||
|
||||
randy = self.pi_creature
|
||||
randy_look_at = ContinualUpdateFromFunc(
|
||||
|
@ -3523,7 +3523,7 @@ class HangingWeightsScene(MovingCameraScene):
|
|||
|
||||
k_tracker = self.k_tracker = VectorizedPoint()
|
||||
t_tracker = self.t_tracker = VectorizedPoint()
|
||||
self.t_tracker_walk = AmbientMovement(t_tracker, direction = RIGHT, rate = 1)
|
||||
self.t_tracker_walk = ContinualMovement(t_tracker, direction = RIGHT, rate = 1)
|
||||
equilibrium_height = springs.get_height()
|
||||
def update_springs(springs):
|
||||
for spring in springs:
|
||||
|
@ -3637,7 +3637,7 @@ class HangingWeightsScene(MovingCameraScene):
|
|||
|
||||
def moving_reference_frame(self):
|
||||
rect = ScreenRectangle(height = 2.1*FRAME_Y_RADIUS)
|
||||
rect_movement = AmbientMovement(rect, direction = LEFT, rate = 2)
|
||||
rect_movement = ContinualMovement(rect, direction = LEFT, rate = 2)
|
||||
camera_frame = self.camera_frame
|
||||
|
||||
self.add(rect)
|
||||
|
@ -4371,7 +4371,7 @@ class ThinkOfHeisenbergUncertainty(PiCreatureScene):
|
|||
self.add()
|
||||
freq = 1
|
||||
continual_anims = [
|
||||
AmbientMovement(time_tracker, direction = RIGHT, rate = 1),
|
||||
ContinualMovement(time_tracker, direction = RIGHT, rate = 1),
|
||||
ContinualUpdateFromFunc(
|
||||
dot_gdw,
|
||||
lambda d : d.scale_to_fit_width(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from constants import *
|
||||
|
||||
from continual_animation.continual_animation import AmbientMovement
|
||||
from continual_animation.continual_animation import ContinualMovement
|
||||
from animation.transform import ApplyMethod
|
||||
from camera.camera import Camera
|
||||
from mobject.vectorized_mobject import VGroup
|
||||
|
@ -184,7 +184,7 @@ class ThreeDScene(Scene):
|
|||
self.camera.set_position(phi, theta, distance, center_x, center_y, center_z)
|
||||
|
||||
def begin_ambient_camera_rotation(self, rate = 0.01):
|
||||
self.ambient_camera_rotation = AmbientMovement(
|
||||
self.ambient_camera_rotation = ContinualMovement(
|
||||
self.camera.rotation_mobject,
|
||||
direction = UP,
|
||||
rate = rate
|
||||
|
|
Loading…
Add table
Reference in a new issue