mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 11:03:03 +08:00
Changed all files to (mostly) conform to PEP8
This commit is contained in:
@ -7,28 +7,30 @@ from utils.rate_functions import smooth
|
||||
from utils.config_ops import instantiate
|
||||
from utils.config_ops import digest_config
|
||||
|
||||
|
||||
class Animation(object):
|
||||
CONFIG = {
|
||||
"run_time" : DEFAULT_ANIMATION_RUN_TIME,
|
||||
"rate_func" : smooth,
|
||||
"name" : None,
|
||||
#Does this animation add or remove a mobject form the screen
|
||||
"remover" : False,
|
||||
#Options are lagged_start, smoothed_lagged_start,
|
||||
#one_at_a_time, all_at_once
|
||||
"submobject_mode" : "all_at_once",
|
||||
"lag_factor" : 2,
|
||||
"run_time": DEFAULT_ANIMATION_RUN_TIME,
|
||||
"rate_func": smooth,
|
||||
"name": None,
|
||||
# Does this animation add or remove a mobject form the screen
|
||||
"remover": False,
|
||||
# Options are lagged_start, smoothed_lagged_start,
|
||||
# one_at_a_time, all_at_once
|
||||
"submobject_mode": "all_at_once",
|
||||
"lag_factor": 2,
|
||||
# Used by EmptyAnimation to announce itself ignorable
|
||||
# in Successions and AnimationGroups
|
||||
"empty" : False
|
||||
"empty": False
|
||||
}
|
||||
|
||||
def __init__(self, mobject, **kwargs):
|
||||
mobject = instantiate(mobject)
|
||||
assert(isinstance(mobject, Mobject))
|
||||
digest_config(self, kwargs, locals())
|
||||
self.starting_mobject = self.mobject.copy()
|
||||
if self.rate_func is None:
|
||||
self.rate_func = (lambda x : x)
|
||||
self.rate_func = (lambda x: x)
|
||||
if self.name is None:
|
||||
self.name = self.__class__.__name__ + str(self.mobject)
|
||||
self.all_families_zipped = self.get_all_families_zipped()
|
||||
@ -37,7 +39,7 @@ class Animation(object):
|
||||
def update_config(self, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
if "rate_func" in kwargs and kwargs["rate_func"] is None:
|
||||
self.rate_func = (lambda x : x)
|
||||
self.rate_func = (lambda x: x)
|
||||
return self
|
||||
|
||||
def __str__(self):
|
||||
@ -58,13 +60,13 @@ class Animation(object):
|
||||
return self
|
||||
|
||||
def update_submobject(self, submobject, starting_sumobject, alpha):
|
||||
#Typically ipmlemented by subclass
|
||||
# Typically ipmlemented by subclass
|
||||
pass
|
||||
|
||||
def get_all_mobjects(self):
|
||||
"""
|
||||
Ordering must match the ording of arguments to update_submobject
|
||||
"""
|
||||
"""
|
||||
return self.mobject, self.starting_mobject
|
||||
|
||||
def get_all_families_zipped(self):
|
||||
@ -75,15 +77,15 @@ class Animation(object):
|
||||
|
||||
def get_sub_alpha(self, alpha, index, num_submobjects):
|
||||
if self.submobject_mode in ["lagged_start", "smoothed_lagged_start"]:
|
||||
prop = float(index)/num_submobjects
|
||||
prop = float(index) / num_submobjects
|
||||
if self.submobject_mode is "smoothed_lagged_start":
|
||||
prop = smooth(prop)
|
||||
lf = self.lag_factor
|
||||
return np.clip(lf*alpha - (lf-1)*prop, 0, 1)
|
||||
return np.clip(lf * alpha - (lf - 1) * prop, 0, 1)
|
||||
elif self.submobject_mode == "one_at_a_time":
|
||||
lower = float(index)/num_submobjects
|
||||
upper = float(index+1)/num_submobjects
|
||||
return np.clip((alpha-lower)/(upper-lower), 0, 1)
|
||||
lower = float(index) / num_submobjects
|
||||
upper = float(index + 1) / num_submobjects
|
||||
return np.clip((alpha - lower) / (upper - lower), 0, 1)
|
||||
elif self.submobject_mode == "all_at_once":
|
||||
return alpha
|
||||
raise Exception("Invalid submobject mode")
|
||||
@ -101,7 +103,8 @@ class Animation(object):
|
||||
|
||||
def set_rate_func(self, rate_func):
|
||||
if rate_func is None:
|
||||
rate_func = lambda x : x
|
||||
def rate_func(x):
|
||||
return x
|
||||
self.rate_func = rate_func
|
||||
return self
|
||||
|
||||
@ -115,7 +118,7 @@ class Animation(object):
|
||||
def is_remover(self):
|
||||
return self.remover
|
||||
|
||||
def clean_up(self, surrounding_scene = None):
|
||||
def clean_up(self, surrounding_scene=None):
|
||||
self.update(1)
|
||||
if surrounding_scene is not None:
|
||||
if self.is_remover():
|
||||
@ -123,16 +126,3 @@ class Animation(object):
|
||||
else:
|
||||
surrounding_scene.add(self.mobject)
|
||||
return self
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user