mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Get rid of instantiate function
This commit is contained in:
parent
84b07bc347
commit
f4ddbef136
5 changed files with 13 additions and 20 deletions
|
@ -5,7 +5,6 @@ import numpy as np
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.config_ops import instantiate
|
|
||||||
from manimlib.utils.rate_functions import smooth
|
from manimlib.utils.rate_functions import smooth
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +25,6 @@ class Animation(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, mobject, **kwargs):
|
def __init__(self, mobject, **kwargs):
|
||||||
mobject = instantiate(mobject)
|
|
||||||
assert(isinstance(mobject, Mobject))
|
assert(isinstance(mobject, Mobject))
|
||||||
digest_config(self, kwargs, locals())
|
digest_config(self, kwargs, locals())
|
||||||
# Make sure it's all up to date
|
# Make sure it's all up to date
|
||||||
|
@ -38,6 +36,12 @@ class Animation(object):
|
||||||
self.all_families_zipped = self.get_all_families_zipped()
|
self.all_families_zipped = self.get_all_families_zipped()
|
||||||
self.update(0)
|
self.update(0)
|
||||||
|
|
||||||
|
def begin_animation(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def end_animation(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@ import warnings
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from manimlib.animation.animation import Animation
|
from manimlib.animation.animation import Animation
|
||||||
from manimlib.constants import *
|
|
||||||
from manimlib.mobject.mobject import Group
|
from manimlib.mobject.mobject import Group
|
||||||
from manimlib.mobject.mobject import Mobject
|
|
||||||
from manimlib.utils.bezier import inverse_interpolate
|
from manimlib.utils.bezier import inverse_interpolate
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.rate_functions import linear
|
from manimlib.utils.rate_functions import linear
|
||||||
|
@ -192,7 +190,7 @@ class AnimationGroup(Animation):
|
||||||
self.run_time = 0
|
self.run_time = 0
|
||||||
else:
|
else:
|
||||||
self.run_time = max([a.run_time for a in sub_anims])
|
self.run_time = max([a.run_time for a in sub_anims])
|
||||||
everything = Mobject(*[a.mobject for a in sub_anims])
|
everything = Group(*[a.mobject for a in sub_anims])
|
||||||
Animation.__init__(self, everything, **kwargs)
|
Animation.__init__(self, everything, **kwargs)
|
||||||
|
|
||||||
def update(self, alpha):
|
def update(self, alpha):
|
||||||
|
@ -262,13 +260,13 @@ class ApplyToCenters(Animation):
|
||||||
def __init__(self, AnimationClass, mobjects, **kwargs):
|
def __init__(self, AnimationClass, mobjects, **kwargs):
|
||||||
full_kwargs = AnimationClass.CONFIG
|
full_kwargs = AnimationClass.CONFIG
|
||||||
full_kwargs.update(kwargs)
|
full_kwargs.update(kwargs)
|
||||||
full_kwargs["mobject"] = Mobject(*[
|
full_kwargs["mobject"] = Group(*[
|
||||||
mob.get_point_mobject()
|
mob.get_point_mobject()
|
||||||
for mob in mobjects
|
for mob in mobjects
|
||||||
])
|
])
|
||||||
self.centers_container = AnimationClass(**full_kwargs)
|
self.centers_container = AnimationClass(**full_kwargs)
|
||||||
full_kwargs.pop("mobject")
|
full_kwargs.pop("mobject")
|
||||||
Animation.__init__(self, Mobject(*mobjects), **full_kwargs)
|
Animation.__init__(self, Group(*mobjects), **full_kwargs)
|
||||||
self.name = str(self) + AnimationClass.__name__
|
self.name = str(self) + AnimationClass.__name__
|
||||||
|
|
||||||
def update_mobject(self, alpha):
|
def update_mobject(self, alpha):
|
||||||
|
|
|
@ -210,8 +210,10 @@ class ComplexFunction(ApplyPointwiseFunction):
|
||||||
)
|
)
|
||||||
ApplyPointwiseFunction.__init__(
|
ApplyPointwiseFunction.__init__(
|
||||||
self,
|
self,
|
||||||
lambda x_y_z: complex_to_R3(function(complex(x_y_z[0], x_y_z[1]))),
|
lambda p: complex_to_R3(function(
|
||||||
instantiate(mobject),
|
complex(p[0], p[1])
|
||||||
|
)),
|
||||||
|
mobject,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ from manimlib.constants import *
|
||||||
from manimlib.mobject.mobject import Group
|
from manimlib.mobject.mobject import Group
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.config_ops import instantiate
|
|
||||||
|
|
||||||
|
|
||||||
class ContinualAnimation(object):
|
class ContinualAnimation(object):
|
||||||
|
@ -15,7 +14,6 @@ class ContinualAnimation(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, mobject, **kwargs):
|
def __init__(self, mobject, **kwargs):
|
||||||
mobject = instantiate(mobject)
|
|
||||||
assert(isinstance(mobject, Mobject))
|
assert(isinstance(mobject, Mobject))
|
||||||
digest_config(self, kwargs, locals())
|
digest_config(self, kwargs, locals())
|
||||||
self.internal_time = 0
|
self.internal_time = 0
|
||||||
|
|
|
@ -2,15 +2,6 @@ import inspect
|
||||||
import itertools as it
|
import itertools as it
|
||||||
|
|
||||||
|
|
||||||
def instantiate(obj):
|
|
||||||
"""
|
|
||||||
Useful so that classes or instance of those classes can be
|
|
||||||
included in configuration, which can prevent defaults from
|
|
||||||
getting created during compilation/importing
|
|
||||||
"""
|
|
||||||
return obj() if isinstance(obj, type) else obj
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_descendent_classes(Class):
|
def get_all_descendent_classes(Class):
|
||||||
awaiting_review = [Class]
|
awaiting_review = [Class]
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Add table
Reference in a new issue