mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Further improvements to initial ContinualAnimations
This commit is contained in:
parent
a954a09857
commit
d34d9abd31
2 changed files with 47 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
from helpers import *
|
||||
from mobject import Mobject
|
||||
from mobject import Mobject, Group
|
||||
import copy
|
||||
|
||||
class ContinualAnimation(object):
|
||||
CONFIG = {
|
||||
|
@ -45,10 +46,32 @@ class ContinualAnimation(object):
|
|||
#To implement in subclass
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def copy(self):
|
||||
return copy.deepcopy(self)
|
||||
|
||||
class ContinualAnimationGroup(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"start_up_time" : 0,
|
||||
"wind_down_time" : 0,
|
||||
}
|
||||
def __init__(self, *continual_animations, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
self.group = Group(*[ca.mobject for ca in continual_animations])
|
||||
ContinualAnimation.__init__(self, self.group, **kwargs)
|
||||
|
||||
def update_mobject(self, dt):
|
||||
for continual_animation in self.continual_animations:
|
||||
continual_animation.update(dt)
|
||||
|
||||
|
||||
class AmbientRotation(ContinualAnimation):
|
||||
CONFIG = {
|
||||
"axis" : OUT,
|
||||
"rate" : np.pi/12, #Radians per second
|
||||
}
|
||||
|
||||
def update_mobject(self, dt):
|
||||
self.mobject.rotate(dt*self.rate, axis = self.axis)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class Scene(object):
|
|||
"save_frames" : False,
|
||||
"output_directory" : MOVIE_DIR,
|
||||
"name" : None,
|
||||
"always_continually_update" : False,
|
||||
}
|
||||
def __init__(self, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
|
@ -121,9 +122,9 @@ class Scene(object):
|
|||
self.clear()
|
||||
###
|
||||
|
||||
def update_continual_animations(self, dt_multiplier = 1):
|
||||
def continual_update(self):
|
||||
for continual_animation in self.continual_animations:
|
||||
continual_animation.update(dt_multiplier*self.frame_duration)
|
||||
continual_animation.update(self.frame_duration)
|
||||
|
||||
def wind_down(self, *continual_animations, **kwargs):
|
||||
wind_down_time = kwargs.get("wind_down_time", 1)
|
||||
|
@ -136,7 +137,11 @@ class Scene(object):
|
|||
lambda ca : ca in continual_animations,
|
||||
self.continual_animations
|
||||
)
|
||||
#
|
||||
|
||||
def should_continually_update(self):
|
||||
return len(self.continual_animations) > 0 or self.always_continually_update
|
||||
|
||||
###
|
||||
|
||||
def extract_mobject_family_members(self, *mobjects):
|
||||
return remove_list_redundancies(list(
|
||||
|
@ -276,10 +281,11 @@ class Scene(object):
|
|||
return [m.copy() for m in self.mobjects]
|
||||
|
||||
def separate_moving_and_static_mobjects(self, *animations):
|
||||
moving_mobjects = self.extract_mobject_family_members(
|
||||
*[anim.mobject for anim in animations] + \
|
||||
self.foreground_mobjects
|
||||
)
|
||||
moving_mobjects = self.extract_mobject_family_members(*it.chain(
|
||||
[anim.mobject for anim in animations],
|
||||
[ca.mobject for ca in self.continual_animations],
|
||||
self.foreground_mobjects,
|
||||
))
|
||||
static_mobjects = filter(
|
||||
lambda m : m not in moving_mobjects,
|
||||
self.mobjects
|
||||
|
@ -372,7 +378,7 @@ class Scene(object):
|
|||
for t in self.get_animation_time_progression(animations):
|
||||
for animation in animations:
|
||||
animation.update(t / animation.run_time)
|
||||
self.update_continual_animations()
|
||||
self.continual_update()
|
||||
self.update_frame(moving_mobjects, static_image)
|
||||
self.add_frames(self.get_frame())
|
||||
self.add(*moving_mobjects)
|
||||
|
@ -395,11 +401,11 @@ class Scene(object):
|
|||
if self.skip_animations:
|
||||
return self
|
||||
|
||||
if self.continual_animations:
|
||||
self.play(*[
|
||||
Animation(ca.mobject, run_time = duration)
|
||||
for ca in self.continual_animations
|
||||
])
|
||||
if self.should_continually_update():
|
||||
for t in self.get_time_progression(duration):
|
||||
self.continual_update()
|
||||
self.update_frame()
|
||||
self.add_frames(self.get_frame())
|
||||
else:
|
||||
self.update_frame()
|
||||
self.add_frames(*[self.get_frame()]*int(duration / self.frame_duration))
|
||||
|
|
Loading…
Add table
Reference in a new issue