mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Use super() in __init__ functions
This commit is contained in:
parent
5403237123
commit
67a33d2e88
3 changed files with 25 additions and 40 deletions
|
@ -49,7 +49,7 @@ class DrawBorderThenFill(Animation):
|
|||
|
||||
def __init__(self, vmobject, **kwargs):
|
||||
self.check_validity_of_input(vmobject)
|
||||
Animation.__init__(self, vmobject, **kwargs)
|
||||
super().__init__(vmobject, **kwargs)
|
||||
|
||||
def check_validity_of_input(self, vmobject):
|
||||
if not isinstance(vmobject, VMobject):
|
||||
|
@ -103,7 +103,7 @@ class Write(DrawBorderThenFill):
|
|||
def __init__(self, mobject, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
self.set_default_config_from_length(mobject)
|
||||
DrawBorderThenFill.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def set_default_config_from_length(self, mobject):
|
||||
length = len(mobject.family_members_with_points())
|
||||
|
@ -117,9 +117,13 @@ class Write(DrawBorderThenFill):
|
|||
|
||||
|
||||
class ShowIncreasingSubsets(Animation):
|
||||
CONFIG = {
|
||||
"suspend_mobject_updating": False,
|
||||
}
|
||||
|
||||
def __init__(self, group, **kwargs):
|
||||
self.all_submobs = list(group.submobjects)
|
||||
Animation.__init__(self, group, **kwargs)
|
||||
super().__init__(group, **kwargs)
|
||||
|
||||
def interpolate_mobject(self, alpha):
|
||||
n_submobs = len(self.all_submobs)
|
||||
|
|
|
@ -39,7 +39,7 @@ class FadeInFrom(Transform):
|
|||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
if direction is not None:
|
||||
self.direction = direction
|
||||
Transform.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def create_target(self):
|
||||
return self.mobject.copy()
|
||||
|
@ -68,7 +68,7 @@ class FadeOutAndShift(FadeOut):
|
|||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
if direction is not None:
|
||||
self.direction = direction
|
||||
FadeOut.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def create_target(self):
|
||||
target = super().create_target()
|
||||
|
@ -94,7 +94,7 @@ class FadeInFromLarge(FadeIn):
|
|||
def __init__(self, mobject, scale_factor=2, **kwargs):
|
||||
if scale_factor is not None:
|
||||
self.scale_factor = scale_factor
|
||||
FadeIn.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def create_starting_mobject(self):
|
||||
start = super().create_starting_mobject()
|
||||
|
@ -118,9 +118,6 @@ class VFadeIn(Animation):
|
|||
opacity=interpolate(0, start.get_fill_opacity(), alpha)
|
||||
)
|
||||
|
||||
def update_mobjects(self, dt):
|
||||
pass
|
||||
|
||||
|
||||
class VFadeOut(VFadeIn):
|
||||
CONFIG = {
|
||||
|
@ -128,6 +125,4 @@ class VFadeOut(VFadeIn):
|
|||
}
|
||||
|
||||
def interpolate_submobject(self, submob, start, alpha):
|
||||
VFadeIn.interpolate_submobject(
|
||||
self, submob, start, 1 - alpha
|
||||
)
|
||||
super().interpolate_submobject(submob, start, 1 - alpha)
|
||||
|
|
|
@ -24,7 +24,7 @@ class Transform(Animation):
|
|||
}
|
||||
|
||||
def __init__(self, mobject, target_mobject=None, **kwargs):
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
self.target_mobject = target_mobject
|
||||
self.init_path_func()
|
||||
|
||||
|
@ -111,9 +111,7 @@ class TransformFromCopy(Transform):
|
|||
"""
|
||||
|
||||
def __init__(self, mobject, target_mobject, **kwargs):
|
||||
Transform.__init__(
|
||||
self, target_mobject, mobject, **kwargs
|
||||
)
|
||||
super().__init__(target_mobject, mobject, **kwargs)
|
||||
|
||||
def interpolate(self, alpha):
|
||||
super().interpolate(1 - alpha)
|
||||
|
@ -134,7 +132,7 @@ class CounterclockwiseTransform(Transform):
|
|||
class MoveToTarget(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
self.check_validity_of_input(mobject)
|
||||
Transform.__init__(self, mobject, mobject.target, **kwargs)
|
||||
super().__init__(mobject, mobject.target, **kwargs)
|
||||
|
||||
def check_validity_of_input(self, mobject):
|
||||
if not hasattr(mobject, "target"):
|
||||
|
@ -157,7 +155,7 @@ class ApplyMethod(Transform):
|
|||
self.check_validity_of_input(method)
|
||||
self.method = method
|
||||
self.method_args = args
|
||||
Transform.__init__(self, method.__self__, **kwargs)
|
||||
super().__init__(method.__self__, **kwargs)
|
||||
|
||||
def check_validity_of_input(self, method):
|
||||
if not inspect.ismethod(method):
|
||||
|
@ -187,17 +185,13 @@ class ApplyPointwiseFunction(ApplyMethod):
|
|||
}
|
||||
|
||||
def __init__(self, function, mobject, **kwargs):
|
||||
ApplyMethod.__init__(
|
||||
self, mobject.apply_function, function, **kwargs
|
||||
)
|
||||
super().__init__(mobject.apply_function, function, **kwargs)
|
||||
|
||||
|
||||
class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
|
||||
def __init__(self, function, mobject, **kwargs):
|
||||
self.function = function
|
||||
ApplyMethod.__init__(
|
||||
self, mobject.move_to, **kwargs
|
||||
)
|
||||
super().__init__(mobject.move_to, **kwargs)
|
||||
|
||||
def begin(self):
|
||||
self.method_args = [
|
||||
|
@ -208,14 +202,12 @@ class ApplyPointwiseFunctionToCenter(ApplyPointwiseFunction):
|
|||
|
||||
class FadeToColor(ApplyMethod):
|
||||
def __init__(self, mobject, color, **kwargs):
|
||||
ApplyMethod.__init__(self, mobject.set_color, color, **kwargs)
|
||||
super().__init__(mobject.set_color, color, **kwargs)
|
||||
|
||||
|
||||
class ScaleInPlace(ApplyMethod):
|
||||
def __init__(self, mobject, scale_factor, **kwargs):
|
||||
ApplyMethod.__init__(
|
||||
self, mobject.scale, scale_factor, **kwargs
|
||||
)
|
||||
super().__init__(mobject.scale, scale_factor, **kwargs)
|
||||
|
||||
|
||||
class ShrinkToCenter(ScaleInPlace):
|
||||
|
@ -225,13 +217,13 @@ class ShrinkToCenter(ScaleInPlace):
|
|||
|
||||
class Restore(ApplyMethod):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
ApplyMethod.__init__(self, mobject.restore, **kwargs)
|
||||
super().__init__(mobject.restore, **kwargs)
|
||||
|
||||
|
||||
class ApplyFunction(Transform):
|
||||
def __init__(self, function, mobject, **kwargs):
|
||||
self.function = function
|
||||
Transform.__init__(self, mobject, **kwargs)
|
||||
super().__init__(mobject, **kwargs)
|
||||
|
||||
def create_target(self):
|
||||
return self.function(self.mobject.copy())
|
||||
|
@ -244,9 +236,7 @@ class ApplyMatrix(ApplyPointwiseFunction):
|
|||
def func(p):
|
||||
return np.dot(p, matrix.T)
|
||||
|
||||
ApplyPointwiseFunction.__init__(
|
||||
self, func, mobject, **kwargs
|
||||
)
|
||||
super().__init__(func, mobject, **kwargs)
|
||||
|
||||
def initialize_matrix(self, matrix):
|
||||
matrix = np.array(matrix)
|
||||
|
@ -262,12 +252,8 @@ class ApplyMatrix(ApplyPointwiseFunction):
|
|||
class ApplyComplexFunction(ApplyMethod):
|
||||
def __init__(self, function, mobject, **kwargs):
|
||||
self.function = function
|
||||
ApplyMethod.__init__(
|
||||
self,
|
||||
mobject.apply_complex_function,
|
||||
function,
|
||||
**kwargs
|
||||
)
|
||||
method = mobject.apply_complex_function
|
||||
super().__init__(method, function, **kwargs)
|
||||
|
||||
def init_path_func(self):
|
||||
func1 = self.function(complex(1))
|
||||
|
@ -284,7 +270,7 @@ class CyclicReplace(Transform):
|
|||
|
||||
def __init__(self, *mobjects, **kwargs):
|
||||
self.group = Group(*mobjects)
|
||||
Transform.__init__(self, self.group, **kwargs)
|
||||
super().__init__(self.group, **kwargs)
|
||||
|
||||
def create_target(self):
|
||||
target = self.group.copy()
|
||||
|
|
Loading…
Add table
Reference in a new issue