Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

scene.apply method, which required switching order or ApplyFunction arguments

Grant Sandersonc99a1dfd6aa9
diff --git a/animation/transform.py b/animation/transform.py
index 8c73bf593..79f7a753d 100644
--- a/animation/transform.py
+++ b/animation/transform.py
@@ -139,7 +139,7 @@ class ScaleInPlace(ApplyMethod):
ApplyMethod.__init__(self, mobject.scale_in_place, scale_factor, **kwargs)
class ApplyFunction(Transform):
- def __init__(self, function, mobject, **kwargs):
+ def __init__(self, mobject, function, **kwargs):
Transform.__init__(
self,
mobject,
@@ -152,7 +152,7 @@ class ApplyPointwiseFunction(Transform):
DEFAULT_CONFIG = {
"run_time" : DEFAULT_ANIMATION_RUN_TIME
}
- def __init__(self, function, mobject, **kwargs):
+ def __init__(self, mobject, function, **kwargs):
digest_config(self, ApplyPointwiseFunction, kwargs)
map_image = copy.deepcopy(mobject)
map_image.points = np.array(map(function, map_image.points))
@@ -164,20 +164,13 @@ class ApplyPointwiseFunction(Transform):
])
class ComplexFunction(ApplyPointwiseFunction):
- def __init__(self, function, *args, **kwargs):
+ def __init__(self, mobject, function, **kwargs):
def point_map(point):
x, y, z = point
c = np.complex(x, y)
c = function(c)
return c.real, c.imag, z
- if len(args) > 0:
- args = list(args)
- mobject = args.pop(0)
- elif "mobject" in kwargs:
- mobject = kwargs.pop("mobject")
- else:
- mobject = Grid()
- ApplyPointwiseFunction.__init__(self, point_map, mobject, *args, **kwargs)
+ ApplyPointwiseFunction.__init__(self, mobject, point_map, *args, **kwargs)
self.name = "ComplexFunction" + to_cammel_case(function.__name__)
#Todo, abstract away function naming'
diff --git a/scene/scene.py b/scene/scene.py
index 20db87f6b..8efb01a71 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -154,6 +154,12 @@ class Scene(object):
animation.clean_up()
return self
+ def apply(self, AnimationClass, *args, **kwargs):
+ self.play(*[
+ AnimationClass(mobject, *args, **kwargs)
+ for mobject in self.mobjects
+ ])
+
def get_frame(self):
return disp.paint_mobject(
CompoundMobject(*self.mobjects), self.background